The general syntax of functions and methods

We can define functions or methods as follows:

accessControl 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 from where it can be accessed. This concept is called access control in Swift and there are three levels of access control. We are going to explain them for methods as follows:

  • Public access: Any entity can access a method that is defined as public if it is in the same module. If an entity is not in the same module, we will need to import the module to be able to call the method. We need to mark our methods and objects as public when we develop ...

Get Swift 3 Functional Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.