swift-playground

How to print to console using swift playground?

本秂侑毒 提交于 2019-11-26 06:34:58
问题 I have been following the Apple Guide for their new language swift, but I don\'t understand why the bar on the right is only showing \"Hello, playground\" and not \"Hello, world\". Can someone explain why the println isn\'t being printed on the right? // Playground - noun: a place where people can play import Cocoa var str = \"Hello, playground\" println(\"Hello, world\"); 回答1: In Xcode 6.3 and later (including Xcode 7 and 8), console output appears in the Debug area at the bottom of the

How to import own classes from your own project into a Playground

让人想犯罪 __ 提交于 2019-11-26 04:38:32
问题 Assume a setup like this: You have an Xcode 6 project, where you\'ve implemented your own classes (say MyView and MyViewController) with both Objective-C and Swift You have added a Playground into your project In the Playground, it\'s possible to import modules (frameworks) like UIKit with the import keyword. How do you enable access to the project\'s other classes from the Playground? Just trying to access project classes directly results with an error message: Use of unresolved identifier \

How to iterate for loop in reverse order in swift?

房东的猫 提交于 2019-11-26 02:29:27
问题 When I use the for loop in Playground, everything worked fine, until I changed the first parameter of for loop to be the highest value. (iterated in descending order) Is this a bug? Did any one else have it? for index in 510..509 { var a = 10 } The counter that displays the number of iterations that will be executions keeps ticking... 回答1: Xcode 6 beta 4 added two functions to iterate on ranges with a step other than one: stride(from: to: by:) , which is used with exclusive ranges and stride

How do I run Asynchronous callbacks in Playground

南楼画角 提交于 2019-11-26 01:26:20
问题 Many Cocoa and CocoaTouch methods have completion callbacks implemented as blocks in Objective-C and Closures in Swift. However, when trying these out in Playground, the completion is never called. For example: // Playground - noun: a place where people can play import Cocoa import XCPlayground let url = NSURL(string: \"http://stackoverflow.com\") let request = NSURLRequest(URL: url) NSURLConnection.sendAsynchronousRequest(request, queue:NSOperationQueue.currentQueue() { response, maybeData,