0Pricing
Swift Academy · Lesson

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)  // 1

All lessons in this course

  1. Defining functions, parameters, labels, default/variadic
  2. Return values & multiple returns via tuples
  3. In-out params & basic error handling (throws)
← Back to Swift Academy