2015-07-20 160 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)