Chapter 6. Functions

Unless you like to spend most of your time repeating yourself, functions are an essential part of any programming language. Swift functions are a cut above their namesake in Objective-C. A Swift function can be standalone or a method belonging to a class, structure, or enum. They can be created inside another function (known as a nested function), can be passed to other functions as parameters, and even returned from functions as a return value. Given their increased importance, saying that functions are now first-class citizens of the Swift world is a fair statement.

In Objective-C, a distinction is made between functions and methods: A function is very much the domain of C code, and methods belong firmly to Objective-C. ...

Get Swift Translation Guide for Objective-C Users: Develop and Design 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.