O'Reilly logo

Learn Swift 2 on the Mac, Second Edition by Waqar Malik

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

Chapter    8

Functions

Functions are self-contained blocks of code that perform a specific task. Swift’s functions are very flexible. They can be very simple, such as the print function, or very complex. Here are some examples:

  • They can be simple C-style functions with no parameter names.
  • They can have local and external parameter names for parameters, similar to Objective-C.
  • They can have parameters that provide default values.
  • They can return multiple values.
  • They can be passed as arguments.
  • They can be returned as a result from other functions.
  • They can have nested functions.

Defining Functions

The general format for a function starts with the keyword func, followed by the name of the function, optional arguments, and an optional return ...

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