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

Get Swift Programming: The Big Nerd Ranch Guide 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.