swift-playground

CABasicAnimation in Swift Playground

南笙酒味 提交于 2019-12-19 06:40:22
问题 Been going nuts trying to get a live view of an animation in a Swift Playground like in the WWDC "Swift Playgrounds" video. I tried to do a UIView.animateWithDuration with no luck so I am now trying to do a CABasicaAnimation because this seems to be what was used in the demo. I'be gotten rid of a lot of confusing errors and have imported the proper frameworks but am still having no luck getting my little circle to do anything but sit still in the center of my XCPShowView . Here is my code:

Swift NSCountedSet init with array bug?

喜夏-厌秋 提交于 2019-12-19 06:02:30
问题 There seems to be a bug in Swift Playground with the use of NSCountedSet. This code works as intended let numbers = [1,2,2,4,6,7,8,8,5,8,1] let set = NSSet(array: numbers) but when I try to create an NSCountedSet in the same fashion var bag = NSCountedSet(array: numbers) I get this error Playground execution failed: /var/folders/bl/1tnlvfzd4mqb9gkpx0h8rxy00000gp/T/lldb/6514/playground599.swift:56:31: error: 'Int' is not identical to 'AnyObject' var bag = NSCountedSet(array: numbers) I did try

NSJSONSerialization not working as expected in a Playground

戏子无情 提交于 2019-12-18 09:12:14
问题 I have to get football game schedule via JSON and extract date of each game of one of the specific universities. I tried: let url = NSURL(string: "SCHOOL URL") let request = NSURLRequest(URL: url!) let session = NSURLSession.sharedSession() let task = session.dataTaskWithRequest(request){ (data, response, error) -> Void in do{ let jsonData = try NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments) if let schedule = jsonData["schedule"] as? [[String: AnyObject]]{ for game in

Swift Update Label (with HTML content) takes 1min

这一生的挚爱 提交于 2019-12-17 18:48:52
问题 I got a small problem, let me start with the code class ViewController: UIViewController { @IBOutlet weak var LBoutput: UILabel! @IBAction func BTclick(sender: AnyObject) { var url = NSURL(string: "http://google.com") println("test0") let getdata = NSURLSession.sharedSession().dataTaskWithURL(url){(data ,response , error) in var htmlContent = NSString(data: data, encoding: NSUTF8StringEncoding) println("test1") println("test2") self.LBoutput.text = "test6" } println("test3") getdata.resume()

Does swift playground support UIKit?

こ雲淡風輕ζ 提交于 2019-12-17 17:34:59
问题 I tried to create a UILabel in playground but failed. Does playground only support OS X development for now? 回答1: YES, it does! File: New > File... > iOS > Source > Playground import UIKit let lbl = UILabel(frame: CGRectMake(0, 0, 300, 100)) lbl.text = "Hello StackOverflow!" Then, save the file. This will trigger the Playground to interpret UI related things. Sometimes you may need to toss in a trailing newline and save again -- its a beta. At this point, the word "UILabel" should appear on

Change in Xcode 10 Playgrounds Variable Initialization change? Are Xcode 10 Playgrounds an interpreter?

别来无恙 提交于 2019-12-17 16:49:57
问题 I've noticed that Playgrounds in Xcode 10 no longer allow for the use of declared, but uninitialized variables. For example: while this code would work in an Xcode 9 playground, in an Xcode 10 playground (at least in Beta 1), it crashes: var myValue: Int //... myValue = 100 print (myValue) // Xcode 9 prints 100 // Xcode 10 reports an error: variables currently must have an initial value when entered at the top level of the REPL Is this the new behavior, or just a bug in the current Xcode 10

Making my function calculate average of array Swift

十年热恋 提交于 2019-12-17 04:31:25
问题 I want my function to calculate the average of my Double type array. The array is called "votes". For now, I have 10 numbers. When I call the average function to get the average of the array votes, it doesn't work. Here's my code: var votes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] func average(nums: Double...) -> Double { var total = 0.0 for vote in votes { total += vote } let votesTotal = Double(votes.count) var average = total/votesTotal return average } average[votes] How do I call the average

Why can't I extract data from media file using AVURLAsset in a Playground?

北战南征 提交于 2019-12-14 03:50:00
问题 In my Playground: import Cocoa import Foundation import AVFoundation var path2 = "/Users/me/Movies/bukesiyi.mp4" var video2 = NSURL(fileURLWithPath: path2, isDirectory: false) // it shows: file:///Users/me/Movies/bukesiyi.mp4 video2.checkResourceIsReachableAndReturnError(nil) // it's true var asset = AVURLAsset(URL: video2) // it shows: <AVURLAsset: 0x7fc0a9f13500, URL = file:///Users/me/Movies/bukesiyi.mp4> asset.tracksWithMediaType(AVMediaTypeVideo) // it's [] asset.readable // it's false

why it cannot show anything in playground in swift 2?

爱⌒轻易说出口 提交于 2019-12-13 15:12:30
问题 I try to use spriteKit to show something in playground in assistant editor. However, nothing showed. Below is the code. And if any one can show the results (a blue rectangle), please inform me. If not, please figure out where the problem is. import UIKit import SpriteKit let view:SKView = SKView(frame: CGRectMake(0, 0, 1000, 800)) let scene:SKScene = SKScene(size: CGSizeMake(1000, 800)) scene.scaleMode = SKSceneScaleMode.AspectFit let blueBox: SKSpriteNode = SKSpriteNode(color: UIColor

Error importing framework in Playground

谁都会走 提交于 2019-12-13 14:46:11
问题 I’m following the instructions for Importing Custom Frameworks into Playground, but I still keep getting "No such module” error. I have tried adding everything in the workspace; a project with just Framework target, project of Cocoa Application with the framework, and just the Framework. I also tried creating a playground in the Application where I imported the framework, I can even import it in other swift file without any problem; but I can’t seem to be able to import it in playground. Can