【发布时间】:2015-07-20 07:39:40
【问题描述】:
以下是使用 Xcode 6.4 针对 iOS 8.4 构建的工作代码
NSURLConnection.sendAsynchronousRequest(urlRequest, queue: NSOperationQueue.mainQueue(), completionHandler: { response, data, error in
if error != nil {
println("there be an error")
} else {
let image = UIImage(data:data)
self.webimage.image = image
}
})
如果我在 Xcode 自动完成时双击方法签名的闭包部分,我最终会处于这种状态:
Xcode 没有将}) 放在闭包的末尾,还添加了-> Void in。
这是 Xcode 6.4 中的一个错误,还是有两种替代的闭包语法?
我什么时候需要completionHandler : { arg, arg arg in 和completionHandler : {(arg,arg,arg) -> Void in //code })
【问题讨论】:
-
如果可以根据您的需求进行定制,这会是一个有用的开始吗? stackoverflow.com/questions/48932152/…