Chapter 6: Functions and Closures
At this point, you can write reasonably complex programs that can make decisions and repeat instruction sequences. You can also store data for your programs using collection types. As the programs you write grow in size and complexity, it will become harder to comprehend what they do.
To make large programs easier to understand, Swift allows you to create functions, which let you combine a number of instructions and execute them by calling a single name. You can also create closures, which let you combine a number of instructions without a name and assign it to a constant or variable.
By the end of this chapter, you'll have learned about functions, nested functions, functions as return types, functions as arguments, ...
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