In-out params & basic error handling (throws)
Mutate arguments with in-out parameters and handle recoverable failures using throws, try, and do/catch.
Intro
This lesson covers in-out parameters (mutate the caller's variable) and basic error handling with throws, try, and do/catch.
inout basics
inout lets a function modify the caller's variable. Call with &name.
func increment(_ value: inout Int) {
value += 1 // mutate caller's variable
}
var count = 0
increment(&count)
print("count =", count) // 1All lessons in this course
- Defining functions, parameters, labels, default/variadic
- Return values & multiple returns via tuples
- In-out params & basic error handling (throws)