Functions

In the program structure section in Lesson 1, we mentioned that functions are a key part of Swift's structure, and are units of code that can accept parameters and can return values. In this section, we'll dive into Swift functions, learning how to implement and call them in the course of a Swift application.

Before diving into Swift function syntax, we should summarize some key points about how functions are used in Swift, and in modern software development generally:

  • Functions are units of code that carry out some specific task.
  • In terms of lines of code, functions should be short. How many lines of code is a maximum for a function has been a topic of debate for decades. However, long functions often do not satisfy the specific task definition. ...

Get Beginning Swift 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.