0Pricing
Swift Academy · Lesson

Functions as First-Class Values

Storing functions in variables, passing as arguments and returning from functions.

Welcome

In Swift, functions are first-class citizens — you can store them in variables, pass them as arguments, return them from other functions, and nest them inside other functions.

Function Types

Every function has a type defined by its parameter and return types: ```swift func add(_ a: Int, _ b: Int) -> Int { a + b } let operation: (Int, Int) -> Int = add print(operation(3, 4)) // 7 ``` The type of `add` is `(Int, Int) -> Int`.

All lessons in this course

  1. Argument Labels and Parameter Names
  2. Default and Variadic Parameters
  3. In-Out Parameters and Multiple Returns
  4. Functions as First-Class Values
← Back to Swift Academy