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
- Argument Labels and Parameter Names
- Default and Variadic Parameters
- In-Out Parameters and Multiple Returns
- Functions as First-Class Values