Why the switch feels bigger than it is
The Swift 6 language mode turns data-race checking from advice into errors. Flip the setting on an app that grew up with DispatchQueue, singletons and delegate callbacks, and the compiler can report hundreds of problems at once. Most of them trace back to a handful of root causes: a global that nobody declared safe, a model class that crosses from a background closure to the main actor, a delegate protocol that predates concurrency. Fix those and whole screens of errors disappear.
The language mode is opt-in per target. Xcode keeps your current mode until you change it, and Apple’s guide on adopting strict concurrency says you can move back to Swift 5 mode, or back to minimal checking, at any point while you work through the list. That makes the migration something you can do in small, shippable steps.
Step 1: know the three checking levels
In the Swift 5 language mode the Strict Concurrency Checking build setting (SWIFT_STRICT_CONCURRENCY) has three values:
- Minimal checks only code that has explicitly adopted concurrency features, such as
Sendableconformances and@MainActor. - Targeted adds strict checks inside code that uses concurrency:
asyncfunctions, actors and@Sendableclosures, the scopes SE-0337 calls strict. - Complete checks the whole module, exactly as the Swift 6 mode does, but reports warnings instead of errors.
In the Swift 6 mode the setting is always complete and the diagnostics are errors. The practical path is to raise the level while staying in Swift 5 mode, fix the warnings, and only then change Swift Language Version to 6.
In a Swift package the same idea is a per-target setting:
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "AppCore",
platforms: [.iOS(.v17)],
targets: [
.target(name: "Models"),
.target(
name: "Networking",
swiftSettings: [.swiftLanguageMode(.v5)]
),
]
)
A tools version of 6.0 puts every target in the Swift 6 mode by default. swiftLanguageMode(.v5) holds one target back while you work on it. For a quick count of warnings without editing anything, pass -strict-concurrency=complete from the command line:
swift build -Xswiftc -strict-concurrency=complete
The swift.org migration strategy also suggests a gentler start: enable single upcoming features in Swift 5 mode, one at a time, so you see one kind of problem at once. The three it names are GlobalConcurrency (SE-0412), InferSendableFromCaptures (SE-0418) and DisableOutwardActorInference (SE-0401). In Xcode they live under Swift Compiler - Upcoming Features.
Step 2: pick the module order
This is where the sources disagree, and it matters for planning.
The swift.org guide recommends starting from the outside: the outermost module, the one nothing else depends on, which is usually the app target. Apple’s guide says the same thing, that it is usually easier to migrate the app first and then the modules it depends on. The reasoning is that changes in a leaf module only have local effects.
Donny Wals takes the opposite view in How to plan a migration to Swift 6. He suggests modularizing first, enabling strict checking in a small package such as your models, and leaving the app target for later, so each step has a short warning list you can reason about.
Both work. This article recommends a mix:
- Start with complete checking as warnings on the app target, without fixing anything, to see where the warnings cluster.
- If most of them point at a shared module (a global logger, a non-
Sendablemodel type, a networking client), fix that module first. The guide itself says dependencies with unsafe global state or types that should be triviallySendableare often the root of many warnings. - Migrate the app target from the UI inward: views and view models first, since they already run on the main thread, then services.
Donny’s other advice is worth taking as is: resolve every warning before flipping the language mode, and get the whole team comfortable with the model instead of leaving it to one person.
Step 3: express what is already true
The guide’s guiding principle for fixing warnings is short: express what is true now. Resist redesigning while you migrate. If a class is only ever touched from the main thread, say so with @MainActor. If a struct only holds values, let it be Sendable. Keep a list of every unsafe opt-out you add; that list becomes your refactoring backlog once the module is clean.
The common errors and their fixes
Global and static variables
Every mutable global is shared state the compiler cannot prove safe. SE-0412 made this an error in Swift 6. You have four honest options, in this order of preference:
import Foundation
let defaultTimeout: Duration = .seconds(30)
@MainActor var lastSyncDate: Date?
final class Settings: Sendable {
static let shared = Settings()
let apiBaseURL = URL(string: "https://example.com")!
}
nonisolated(unsafe) var legacyLaunchCount = 0
Make it a let of a Sendable type if it never changes. Isolate it to a global actor if only one actor touches it. Make the singleton’s type Sendable if its state is immutable. Use nonisolated(unsafe) only when an external lock already protects it, and treat each use as a debt.
The most common case in real apps is a singleton of a non-Sendable class:
final class ImageLoader {
static let shared = ImageLoader()
}
Swift 6 rejects this with “static property ‘shared’ is not concurrency-safe”. If the loader is used from UI code, mark the class @MainActor. If it has mutable state used from many places, it is a candidate for an actor, which the next section covers.
Crossing isolation boundaries
You pass a value from one isolation domain to another: from the main actor into an actor, or from a view model into a Task that runs elsewhere. The value has to be Sendable, or the compiler has to prove nothing else still uses it.
import Foundation
struct Article: Sendable {
let id: UUID
var title: String
}
actor ArticleStore {
private var articles: [UUID: Article] = [:]
func save(_ article: Article) {
articles[article.id] = article
}
}
@MainActor
final class EditorModel {
var draft = Article(id: UUID(), title: "")
let store = ArticleStore()
func save() async {
await store.save(draft)
}
}
Structs and enums made of Sendable values are implicitly Sendable inside a module, but a public type needs the conformance written out. That is why so many warnings vanish when you add Sendable to a few model types in a shared package.
For a class with a lock you wrote yourself, @unchecked Sendable is the escape hatch:
import Foundation
final class Counter: @unchecked Sendable {
private let lock = NSLock()
private var value = 0
func increment() {
lock.withLock { value += 1 }
}
}
On iOS 18 and later, Mutex from the Synchronization framework gives you the same protection with a checked Sendable conformance, so prefer it when your deployment target allows.
Protocol conformance isolation mismatch
A @MainActor view model conforms to a delegate protocol whose requirements are nonisolated. The compiler cannot let a background caller run main-actor code, so it errors.
Swift 6.2 added isolated conformances (SE-0470). The conformance itself is restricted to the main actor, and the compiler stops you from using it anywhere else:
protocol FeedDelegate: AnyObject {
func feedDidUpdate(_ items: [String])
}
@MainActor
final class FeedViewModel: @MainActor FeedDelegate {
var items: [String] = []
func feedDidUpdate(_ items: [String]) {
self.items = items
}
}
Before 6.2, or when the protocol is from a framework you trust to call on the main thread, @preconcurrency on the conformance silences the mismatch and inserts a runtime check that crashes if a call arrives off the main actor:
@MainActor
final class LegacyViewModel: @preconcurrency FeedDelegate {
var items: [String] = []
func feedDidUpdate(_ items: [String]) {
self.items = items
}
}
The third option is a nonisolated method that asserts with MainActor.assumeIsolated. Matt Massicotte ranks the choices in Conforming to Protocols: make the type nonisolated if you can, then an isolated conformance, then @preconcurrency, and assumeIsolated last because it is verbose and adds Sendable friction. That order is a good default.
Callback APIs
Wrap completion handlers with a checked continuation so the rest of your code can await them:
import Foundation
func fetchLegacy(completion: @escaping @Sendable (Result<Data, any Error>) -> Void) {
completion(.success(Data()))
}
func fetch() async throws -> Data {
try await withCheckedThrowingContinuation { continuation in
fetchLegacy { result in
continuation.resume(with: result)
}
}
}
Donny Wals warns about a quiet behavior change here: if the old code fired several callbacks in parallel and the new code awaits them in a loop, you have made the work sequential. Use async let or a task group when the original ran concurrently.
Dependencies you do not control
A third-party module that has not adopted Swift 6 can produce errors you cannot fix in your own code. @preconcurrency import downgrades them. LegacyAnalytics stands in for any unmigrated module:
@preconcurrency import LegacyAnalytics
In the Swift 6 mode, Sendable errors about that module’s types become warnings. In Swift 5 mode they go away entirely. The guide’s incremental adoption chapter lists the same tool for protocol-conformance mismatches with unmigrated modules. Treat every @preconcurrency import as temporary and revisit it each time you update the package.
Before you reach for it, check whether a newer version of the package already supports Swift 6. Many popular packages do, and Apple’s guide points to Swift Package Index, which shows each package’s Swift 6 compatibility.
For Objective-C frameworks, many Apple APIs carry isolation annotations already. Where they do not, the same @preconcurrency tools apply, and Massicotte’s problematic patterns post adds a caution: Objective-C completion handlers that the compiler translates to async can run on a background thread unless the type is main-actor isolated or Sendable.
Traps and edge cases
@preconcurrencyis a runtime check. On a conformance, it crashes if a call arrives from the wrong isolation. That is better than a silent race, but test the paths that use it.- Migrated code adds runtime checks. SE-0423 makes the compiler emit a runtime assertion wherever a synchronous isolated function can be reached from code without strict checking. A new crash at that check after migration usually means an old caller, often an Objective-C or Swift 5 callback, is reaching main-actor code from a background queue. The crash replaces a data race you already had.
- Do not make everything an actor. Donny Wals and Massicotte agree: an actor makes every access
async, which spreads through the codebase. Use one only for mutable state shared across isolation domains. MainActor.runis rarely needed. Massicotte points out that marking the function@MainActorlets the compiler insert the hop for you.- Blocking on async work deadlocks.
DispatchSemaphoreorDispatchGroup.wait()around anawaitcan hang the cooperative thread pool. - Split isolation. Putting some properties of a type on the main actor and leaving others nonisolated creates more problems than it solves. Isolate the whole type.
A newer path: Swift 6.2 settings
Swift 6.2 and Xcode 26 added the Approachable Concurrency build setting and a Default Actor Isolation setting that can make a whole module @MainActor by default. They change how much of this work you face, and they come with their own trade-offs. The approachable concurrency article covers them. For an existing app, finish the migration with explicit annotations first, then decide.
Migration checklist
| Step | Done when |
|---|---|
| Turn on complete checking in Swift 5 mode for one target | You know where the warnings cluster |
| Fix globals and singletons | No “not concurrency-safe” warnings |
Mark UI types @MainActor |
View models and controllers are isolated as a whole |
Add Sendable to model types, public ones explicitly |
Values cross actors without warnings |
| Fix delegate conformances | Isolated conformance, @preconcurrency, or a nonisolated type |
| Wrap callbacks in continuations | No concurrency lost compared with the old code |
@preconcurrency import for unmigrated modules |
Each one has a note to remove it later |
| Set Swift Language Version to 6 | The target builds with zero concurrency warnings |
| Move to the next module | Repeat, starting with modules the warnings pointed at |
Sources and further reading
- Adopting strict concurrency in Swift 6 apps Apple Developer Documentation
- Migration Strategy Swift Concurrency Migration Guide, swift.org
- Common Compiler Errors Swift Concurrency Migration Guide, swift.org
- Incremental Adoption Swift Concurrency Migration Guide, swift.org
- How to plan a migration to Swift 6 Donny Wals
- Problematic Swift Concurrency Patterns Matt Massicotte
- Concurrency Step-by-Step: Conforming to Protocols Matt Massicotte
- SE-0337: Incremental migration to concurrency checking Swift Evolution
- SE-0423: Dynamic actor isolation enforcement from non-strict-concurrency contexts Swift Evolution
- SE-0412: Strict concurrency for global variables Swift Evolution
- SE-0470: Global-actor isolated conformances Swift Evolution