5 Functions
Functions are the basic type of subroutines in Swift. They offer an encapsulation for reusable chunks of code, often enriched with input and output parameters.
We have arrived at another chapter of utmost importance, in which you will learn about functions—arguably the backbone of modular programming. In this chapter, you will learn how to define and call functions in Swift and about options for parameterization. But we won’t stop there: Your journey will reach beyond vanilla functions. You will learn how to use higher-order functions that accept other functions as parameters, as well as closures that offer an express syntax. Generic functions, which allow flexibility in data types, are also in our scope.
For those of you new to programming, ...
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