Syntax
In this section, we will deep dive into Swift function and method syntax. Boring stuff alert! To make it a little more interesting, revisit or remember the function definition in mathematics and compare the functions and methods you write to math functions.
If you think that you already know the details or if it is not that interesting for you now, you can fast read or skip this first section, and go to the Return values from functions section of this chapter as it is directly related to FP.
Let's get it over with! We define functions or methods as the following:
accessControl methodForm func functionName(parameter: ParameterType) throws -> ReturnType { }
As we know already, when functions are defined in objects they become methods.
The first step to define a method is to tell the compiler where it can be accessed. This concept is called access control in Swift and there are five levels of access control. We are going to explain them for methods as follows:
- open and public access: Any...