Functions as Return Types
Now that you have more experience with functions and closures, recall from Chapter 12 that every function has a function type.
A function type defines a function’s or closure’s parameter and return types.
For example, a function that takes a String argument and returns an Int has the function type of (String) -> Int.
Function types are frequently used to determine what sort of closure you need to satisfy a given parameter’s type or what sort of function needs to be returned.
In Swift, functions are first-class objects. One implication of this is that functions can return other functions as their return type. Remember your little town of Knowhere? It is time to make a function to improve your town. You are ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access