In-Out Parameters and Multiple Returns
Mutating arguments with inout and returning multiple values via tuples.
Welcome
Swift functions normally work with copies of values. `inout` parameters let a function mutate the caller's variable directly. Tuples let functions return multiple values at once.
The inout Keyword
Mark a parameter `inout` to mutate the original:
```swift
func doubleInPlace(_ value: inout Int) {
value *= 2
}
var x = 5
doubleInPlace(&x)
print(x) // 10
```
The `&` prefix at the call site signals the variable may be mutated.
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