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():
![](https://static.packt-cdn.com/products/9781789348668/graphics/assets/275366f0-7def-4563-8aa6-dc0d60d41146.png)
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 see on screen:
![](https://static.packt-cdn.com/products/9781789348668/graphics/assets/d904534d-7e9a-49c8-87ac-f3efc7c9ad1b.png)
That's it! We just created our first function and called it. However, functions can do so much more. We can add what is called a parameter to a function. A parameter allows us to accept data types inside...