I wanted to experiment with using NSURLSession to get RSS data, to see what that would look like. I wrote a chunk of code in a Playground, and when that didn't work I gutted the completion handler code and put in a print("hello, world") to verify the block was getting run.
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration())
let task = session.dataTaskWithURL(NSURL(string:"http://apod.nasa.gov/apod.rss")!, completionHandler:
{(data:NSData?, response:NSURLResponse?, error:NSError?) in
print("hello, world")
}
)!
task.resume()
In a Playground, nothing gets printed to the console. However I dropped this code into an Xcode project and it worked just fine. Why?