let callActionHandler = { (action:UIAlertAction!) -> Void) in
let alertMessage = UIAlertController(title: "Service Unavailable", message: "Sorry, the call feature is not available yet. Please retry later", preferredStyle: UIAlertControllerStyle.Alert)
alertMessage.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alertMessage, animated: true, completion: nil)
};
// Code Snippet 1
let callAction = UIAlertAction(title: "Call" + "123-000-\(indexPath.row)", style: UIAlertActionStyle.Default ) { (action:UIAlertAction!) -> Void in
println("check this out")
}
// Code Snippet 2
let callAction = UIAlertAction(title: "Call" + "123-000-\(indexPath.row)", style: UIAlertActionStyle.Default, handler: { (action:UIAlertAction!) -> Void in
println("Lets check this out")
})
// Code Snippet 3
let callAction = UIAlertAction(title: "Call" + "123-000-\(indexPath.row)", style: UIAlertActionStyle.Default , handler: callActionHandler)
- 这里有三个代码片段,我的疑问是:
- 代码片段1和代码片段2之间的区别是什么?
- 在代码片段1和代码片段2中,哪一个更好地表示并应该被使用?
- 代码片段1究竟是什么意思?它是Swift中的某种属性(完成)观察吗?
- iOS8希望我们按照代码片段1的方式编写,即当我在Xcode自动完成时按下回车键,它会转换为代码片段1。我们应该使用代码片段1还是仍然喜欢使用代码片段2/3,因为它们更容易理解?
谢谢