December 2018
Intermediate to advanced
414 pages
10h 19m
English
Callbacks, as mentioned, allow us to handle asynchronous operations by specifying what should happen when that operation is completed. Simply put, a callback is any piece of executable code that is passed to a function that will call it at some later point, either synchronously or asynchronously. As an example of synchronous callback, in Chapter 3, Diving into Foundation and the Standard Library we used the forEach method available on Array objects:
// Using forEach with a closure:(1...5).forEach { value in print("\(value)")}
This could be equivalently rewritten as follows, where we replace the closure with a function:
// The above is equivalente to this:func printValue<T>(val : T) { print("\(val)") }(1...5).forEach(printValue) ...Read now
Unlock full access