12 Functions
A function is a named set of code that is used to accomplish some specific task. The function’s name describes the task the function performs. You have already used some functions, such as print(), which is a function provided to you by Swift. Other functions are created in code you write.
Functions execute code. Some functions define arguments that you can use to pass in data to help the function do its work. Some functions return something after they have completed their work. You might think of a function as a little machine. You turn it on and it chugs along, doing its work. You can feed it data and, if it is built to do so, it will return a new chunk of data that results from its work.
Functions are an extremely ...
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