(a) Autoclosure:
Autoclosure can automatically package a sentence into a closure. However, the notation with input parameters is not supported
func Autoclosure (_ Check: @autoclosure (),Bool) { if check () { print ( "true") } }
You can write it directly at this time:
Autoclosure (2>3)
(b) @escaping:
In the previous version of the closure of the time without adding @escaping. The current version, if the closure does not have a callback parameter return value, is not required @escaping. But if the closure passes the parameters. There will be a hypothesis. That is, the contents of the block in the parameter are completed before the function is returned. This means that the call to block is synchronized.
Simply put, if the closure is called before the end of the function, it is noescape.
Closures are called after the function is completed, where the call exceeds the scope of the function and is the escape closure.
A callback that ends after a network request is escaped. The closure is executed after a period of time since the request was initiated.
All closures in the swift3.0 are default non-escaping and do not require @noescape. If it's escaping, @escaping says.
Delay operation, Network load, etc. all need @escaping.
Func clorse (Completion: @escaping (_ JSON: [String])()) {Let Workingqueue= dispatchqueue (Label:"Workingqueue") Workingqueue.async {//deferred OperationPrint"work hard") Thread.Sleep (fortimeinterval:2.0) Let JSON= ["AC","MYM"] DispatchQueue.main.async {print ("End Work") //main thread Update callbackcompletion (JSON)}} }
Swift3.0-closure's @autoclosure and @escaping