许多Cocoa和CocoaTouch方法在Objective-C中将完成回调实现为块,在Swift中将闭包实现为闭包。但是,当在Playground中尝试这些时,从不调用完成。例如:
// 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, error in
// This block never gets called?
if let data = maybeData {
let contents = NSString(data:data, encoding:NSUTF8StringEncoding)
println(contents)
} else {
println(error.localizedDescription)
}
}
我可以在我的游乐场时间线中看到控制台输出,但我的完成块中的println
从未被调用过……
https://stackoverflow.com/questions/24058336
复制相似问题