Sendable & Swift 6 Data-Race Safety
Understand the Sendable checks behind most Swift 6 errors — and how to fix them properly.
A Sendable type is safe to share across concurrency domains. Value types made of Sendable members are Sendable automatically; classes must be final with immutable stored properties, or protected by an actor.
Typical Swift 6 fixes: turn the class into a struct, make it an actor, isolate it to @MainActor, or — only as a last resort with manual locking — mark it @unchecked Sendable.
1// ✅ Automatically Sendable
2struct Order: Sendable {
3 let id: UUID
4 let total: Decimal
5}
6
7// ✅ Final class with immutable state
8final class AppConfig: Sendable {
9 let apiBaseURL: URL
10 init(apiBaseURL: URL) { self.apiBaseURL = apiBaseURL }
11}
12
13// ❌ Error in Swift 6: mutable class captured by a concurrent task
14// final class Counter { var value = 0 }
15
16// ✅ Fix: make it an actor
17actor Counter {
18 private(set) var value = 0
19 func increment() { value += 1 }
20}Common pitfalls
- @unchecked Sendable silences the compiler but not the bug — you are responsible for thread safety.
- Migrate module by module: enable strict concurrency warnings first, then switch to the Swift 6 language mode.
Still unclear? Ask BeeAI about Sendable & Swift 6 Data-Race Safety.
Get a tailored explanation, or paste your own code for a Swift 6 review. Free members get daily questions — Pro is unlimited.
Related topics
Protect mutable state from data races — only one task touches an actor's state at a time.
Guarantee UI code runs on the main thread — and understand Swift 6.2 default MainActor isolation.
Value types vs reference types — and why SwiftUI and Swift concurrency favor structs.
Become a Founding Pro member: unlimited BeeAI, upcoming Swift paths and every new reference entry first.
See Pro Plans