Sending values across actors swift-6.4 / ios-26
Lesson 5 / 9
Unit 2 · Strict Concurrency

Sending values across actors

When you hand a value from one actor to another, the compiler needs a promise that no one else can mutate it along the way. In Swift 6 that promise is the Sendable protocol — and the checker is on by default.

Why the compiler cares

A data race is two tasks touching the same memory at once, with at least one writing. Actors serialize access to their own state, but the moment a reference type crosses an actor boundary, both sides could hold it. Sendable is how you prove that can't cause a race.

Rule of thumb
Value types of Sendable members are Sendable for free. Reference types must opt in — and back it up.

Your turn

The Ledger actor on the right won't compile: Entry is a class being sent into the actor. Make Entry safe to send, then run the hidden tests.

Hint available in the Tutor panel — try it yourself first.

Ledger.swift Swift Testing
// Fix Entry so it can cross the actor boundary.
final class Entry {          // ⌘ make me Sendable
    let amount: Decimal
    let memo: String
    init(amount: Decimal, memo: String) {
        self.amount = amount
        self.memo = memo
    }
}

actor Ledger {
    private var entries: [Entry] = []
    func record(_ entry: Entry) {
        entries.append(entry)
    }
    var total: Decimal {
        entries.reduce(0) { $0 + $1.amount }
    }
}
Console Ready · runs in a sandboxed Swift container
Press Run to compile against the hidden test suite.