April 2017
Intermediate to advanced
316 pages
9h 33m
English
Closures can capture variables and constants from the surrounding context in which they are created. Closures can refer to these variables and modify them within their body, even if the original scope that defined variables no longer exists.
A closure is said to escape a function when the closure is passed as an argument to the function but is called after the function returns. One way that a closure can escape is by being stored in a variable that is defined outside the function.
The following is an example of escaping closures, in other words, completion handlers:
func sendRequest(completion: @escaping (_ response: String?, _ error: Error?) -> Void) { // execute some time consuming operation, if successfull { completion("Response", ...Read now
Unlock full access