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

Sending values across actors

Note

Unit 2 · Strict Concurrency. This lesson assumes you've met actors in lesson 2.3.

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.

Coming from Kotlin

Coroutines lean on discipline and @Synchronized; the compiler won't stop you from sharing a mutable object across threads. Swift 6 makes that a compile error.

Tip

Rule of thumb — value types made of Sendable members are Sendable for free. Reference types must opt in, and back it up (immutability, or your own locking).

Your turn

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

Make Entry sendable
Edit the code on the right, then run the hidden tests.

Once the tests pass, you've shipped a race-free value type — the same pattern you'll use for the Note model in the Ripple project.

Ledger.swiftSwift Testing
ConsoleReady · runs in a sandboxed Swift container
Press Run to compile against the hidden test suite.