WHAT YOU WILL LEARN IN THIS CHAPTER:
Array’s three closure functions:
One of the important features in Swift is the closure. Closures are self-contained blocks of code that can be passed to functions to be executed as independent code units. Think of a closure as a function without a name. In fact, functions are actually special cases of closures.
Swift offers various ways to optimize closures so that they are brief and succinct. The various optimizations include the following:
The best way to understand closures is to use an example. Suppose you have the following array of integers:
let numbers = [5,2,8,7,9,4,3,1]
Assume you want to sort this array in ascending order. You could write your own function to perform the sorting, or you could use the
sorted() function available ...