2015-07-20 162 views
1

下面是内置反对使用的XCode 6.4Xcode中关闭自动完成问题

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的自动完成它,我在此状态下结束单击方法签名的封闭部分IOS 8.4工作代码:

enter image description here

Xcode中并没有把})在封闭的末端,还增加了-> Void in。这是Xcode 6.4中的一个错误吗?还是有闭包的两种替代语法?

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

+0

如果可以按照您的需求进行自定义,这是否会对您有所帮助? https://stackoverflow.com/questions/48932152/xcode-auto-complete-for-blocks-within-a-block-and-the-blocks-theyre-in –

回答

4

是Xcode的自动完成你的指令是在方式“后倒闭的风格。”

从Apple文档:

如果你需要一个封闭表达式传递给函数作为 函数的最后一个参数和封盖表现为长,它可以 是它写成一个尾随有用取而代之。拖地的 封闭是外(后)写 的功能的括号调用它支持

如果您想了解更多关于尾随关闭,请这里的DOC报告封闭表达式: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Closures.html(参考部分Trailing Closures)