#55: inout Parameters in Swift
An inout parameter lets a function modify the variable passed by the caller.
func clamp(_ value: inout Int, min: Int, max: Int) {
value = Swift.max(min, Swift.min(max, value))
}
var score = 120
clamp(&score, min: 0, max: 100)
At the call site you use & to make the mutation explicit.
This is useful for algorithms and helpers that conceptually operate on an existing value, but it should still be used sparingly since return values are often simpler to reason about.