O'Reilly logo

Swift Programming: The Big Nerd Ranch Guide by John Gallagher, Matthew Mathias

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required