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)
- Here we have 3 Code Snippets, my doubts are:
- What is the difference between Code Snippet 1 and Code Snippet 2 ?
- Which out of Snippet 1 or Snippet 2 is a better representation and should be used ?
- What does Code Snippet 1 exactly mean? Is it some sort of property (completion) observing in swift?
- The way iOS8 wants us to write is shown in Snippet 1, i.e., when I press enter while Xcode autocompletes, it gets converted to Snippet 1. Should we use Code Snippet 1 or still prefer using Snippet 2/3 as they are easily understood?
Thanks