Functions

Now, it is time to get into an enjoyable part of programming and learn how to write functions. Functions are self-contained pieces of code that you want to run on something. In Swift 3, Apple made a change to how you should write functions. All of the functions we will write in this chapter will perform an action (think of verbs). Let's create a simple function called greet():

This example is a basic function with a print statement in it. In programming, functions do not run until you call them. We call a function by merely calling its name. So, let's call greet, as follows:

greet()

Once we add this to the code, this is what we'll ...

Get iOS 12 Programming for Beginners - Third 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.