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, ...

Get iOS 14 Programming for Beginners - Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.