Last active
December 27, 2015 01:16
-
-
Save gavi/4c33433e2b7f68d96142 to your computer and use it in GitHub Desktop.
Running asynchronous code in Xcode Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import XCPlayground | |
// Updated for Swift 2.0 | |
let url:NSURL!=NSURL(string: "http://objectgraph.com") | |
NSURLSession.sharedSession().dataTaskWithURL(url) { data, response, error in | |
print(NSString(data: data!, encoding: NSUTF8StringEncoding)) | |
print(error) | |
print(response) | |
}.resume() | |
print("This line is printed first as the network call is not complete") | |
//This will make sure your playground runs indefinitely | |
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment