Xcode关闭自动完成问题

cod*_*boy 2 xcode ios swift xcode6

以下是使用 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
    }
})
Run Code Online (Sandbox Code Playgroud)

如果我在 Xcode 自动完成时双击方法签名的关闭部分,我最终会处于这种状态:

在此处输入图片说明

Xcode 并没有放在})最后关闭并且还添加了-> Void in.

这是 Xcode 6.4 中的错误还是闭包有两种替代语法?

我什么时候需要completionHandler : { arg, arg arg incompletionHandler : {(arg,arg,arg) -> Void in //code })

Jem*_*ems 5

Xcode 自动完成指令的方式是“尾随闭包样式”。

从苹果文档:

如果您需要将闭包表达式作为函数的最终参数传递给函数,并且闭包表达式很长,那么将其写为尾随闭包会很有用。尾随闭包是一个闭包表达式,写在它支持的函数调用的括号之外(和之后)

如果您想了解有关尾随闭包的更多信息,请在此处向文档报告:https : //developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html (参见尾随闭包部分)