Default main actor isolation in an existing iOS app: what changes and what breaks
Enable default main actor isolation and Approachable Concurrency in an existing iOS app: where code runs afterwards, and the Codable and protocol errors.
· 8 min read
- Swift concurrency
- Swift
- Xcode
Since Xcode 26, a new app project gets two build settings an older project doesn’t: Default Actor Isolation set to MainActor, and Approachable Concurrency set to Yes. Apple’s advice applies to existing projects as much as new ones, but Xcode doesn’t flip the settings for you, and turning them on is a source-breaking change. The errors you get are not the familiar “non-Sendable type crossing an actor boundary”. They are about where code runs, and about protocol conformances.
This article explains what the two settings do, how to tell where a function runs once they’re on, and the errors you will meet in a real app, with the fixes. The details come from the Swift evolution proposals (SE-0461, SE-0466, SE-0470), Apple’s Build Settings Reference, the Swift compiler’s documentation and changelog, and the two WWDC25 sessions on the subject, “Embracing Swift concurrency” and “Code-along: Elevate an app with Swift concurrency”. We could not compile Swift where we wrote this, so build the snippets in Xcode before relying on them.
What the two settings do
Default Actor Isolation (SWIFT_DEFAULT_ACTOR_ISOLATION) is SE-0466, shipped in Swift 6.2. With the value MainActor, every declaration in the module that has no isolation of its own is inferred @MainActor: functions, classes, structs, enums, protocols, static properties and the types nested inside them. The only values are MainActor and nonisolated, and an existing project is at nonisolated, which is the behaviour you have today. Code imported from other modules is unaffected by your choice.
The exceptions matter later. The default does not apply to anything with explicit or inherited isolation, to anything inside an actor, to types nested in a nonisolated type, or to a type whose declaration directly conforms to a protocol that inherits SendableMetatype, which includes every protocol that inherits Sendable. That last rule is why a CodingKeys enum still compiles: CodingKey inherits Sendable, so the enum stays nonisolated.
Approachable Concurrency (SWIFT_APPROACHABLE_CONCURRENCY) is a bundle. Apple’s Build Settings Reference lists five upcoming features: DisableOutwardActorInference, GlobalActorIsolatedTypesUsability, InferSendableFromCaptures, InferIsolatedConformances and NonisolatedNonsendingByDefault, and says the first three are always on in the Swift 6 language mode. So if your app is already in Swift 6 mode, the setting changes exactly two things:
| Upcoming feature | Proposal | What it changes |
|---|---|---|
NonisolatedNonsendingByDefault |
SE-0461 | A nonisolated async function runs on the caller’s actor instead of always hopping to the cooperative thread pool |
InferIsolatedConformances |
SE-0470 | A @MainActor type’s conformances are themselves main-actor isolated, unless the protocol inherits SendableMetatype (which Sendable does) or every requirement is satisfied by a nonisolated member |
The two settings are independent. Apple’s advice is Approachable Concurrency for every target, and MainActor default isolation for the app target and other UI-focused modules. In a package, .defaultIsolation needs swift-tools-version: 6.2; .enableUpcomingFeature has existed since tools version 5.8, though these two features need the Swift 6.2 compiler:
// Package.swift
.target(
name: "AppFeature",
swiftSettings: [
.defaultIsolation(MainActor.self), // MainActor.self or nil
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
.enableUpcomingFeature("InferIsolatedConformances"),
]
)
Where a function runs afterwards
Before SE-0461, a nonisolated async function never ran on an actor. Calling one from the main actor meant hopping to the cooperative pool and back, whether or not you wanted it, and the hop was where many Sendable errors came from: everything you passed in had to be safe to send to another thread.
With NonisolatedNonsendingByDefault, a nonisolated async function runs on the caller’s actor. Its arguments don’t cross an isolation boundary, so they don’t need to be Sendable. If you want the old behaviour, you ask for it with @concurrent:
// Built with default MainActor isolation and Approachable Concurrency.
import UIKit
nonisolated struct Report { // see Error 1 for why
let rows: [String]
}
nonisolated func parse(_ data: Data) async -> Report {
// Runs on whatever actor called it. From a @MainActor caller,
// #isolation is Optional(Swift.MainActor).
/* … */
}
@concurrent
func render(_ report: Report) async -> UIImage {
// Always leaves the caller's actor for the cooperative pool.
// #isolation is nil; arguments and result are Sendable-checked.
/* … */
}
final class ReportViewModel { // inferred @MainActor
var image: UIImage?
func load(_ data: Data) async {
let report = await parse(data) // no hop
image = await render(report) // hops off, then back
}
}
@concurrent implies nonisolated, applies only to async functions, and can’t be combined with @MainActor or an isolated parameter. Task { } keeps the isolation of the code that creates it, so a task started from a @MainActor method runs on the main actor; Task.detached { } is nonisolated. A Task created inside a nonisolated async function does not inherit the caller’s actor, even though the function itself ran on it.
The important consequence is that turning the feature on can move work onto the main thread. Any nonisolated async function that was doing CPU work on the pool, because that is where it happened to land, now does it on the main actor when called from the UI. Usually nothing fails to compile; the exception SE-0461 notes is a nonisolated async function that passes non-Sendable state on to an @concurrent function. The common symptom is that the app starts to hang on the operations that used to be off-thread.
The compiler has a migration mode for exactly this. Building with -enable-upcoming-feature NonisolatedNonsendingByDefault:migrate emits warnings with fix-its that add @concurrent to existing nonisolated async functions and closures, so behaviour is preserved. In an app target the flag goes in Other Swift Flags. For a package, swift package migrate --to-feature NonisolatedNonsendingByDefault applies the fix-its and updates the manifest, though the migration guide still marks that command as in development. Treat each @concurrent as a question: does this function have to leave the actor? A function that awaits a network call is waiting, not working, and is fine on the main actor. One that decodes a large image or sorts a hundred thousand rows should keep it.
Error 1: a Codable model decoded off the main actor
A model type with no annotations is now @MainActor:
struct Order: Codable { // inferred @MainActor
let id: String
let total: Int
}
With InferIsolatedConformances, its Encodable and Decodable conformances are main-actor isolated too, and an isolated conformance can only be used by code running on that actor. Decoding on the main actor is fine: JSONDecoder.decode(_:from:) has no Sendable constraint on its type parameter, so it accepts the isolated conformance. Decoding anywhere else does not compile:
@concurrent
func fetchOrders(from url: URL) async throws -> [Order] {
let (data, _) = try await URLSession.shared.data(from: url)
return try JSONDecoder().decode([Order].self, from: data)
// error: main actor-isolated conformance of 'Order' to 'Decodable'
// cannot be used in nonisolated context
}
A data transfer object has nothing to do with the UI, so take it out of the default:
nonisolated struct Order: Codable {
let id: String
let total: Int
}
nonisolated on a type declaration arrived in Swift 6.1 (SE-0449). It covers every member and, under the MainActor default, the types nested inside. The struct is no longer Sendable through main-actor isolation, but a non-public struct with Sendable stored properties is implicitly Sendable anyway.
If the type really is a main-actor model class, keep it isolated and decode on the main actor. Decoding a response of ordinary size there costs nothing you will notice.
Error 2: a worker type that should run in the background
The second failure is a type whose whole job is work off the main thread. Under the default it is @MainActor, so everything it does runs on the main actor. You could mark individual methods @concurrent, which makes them nonisolated. But a type with no business on the main actor is clearer as a nonisolated type. This is based on Apple’s WWDC25 code-along, which marks the type and puts @concurrent on the method that does the work:
nonisolated struct PhotoProcessor {
@concurrent
func process(_ data: Data) async -> ProcessedPhoto? {
async let sticker = extractSticker(from: data)
async let colors = extractColors(from: data)
guard let sticker = await sticker, let colors = await colors else { return nil }
return ProcessedPhoto(sticker: sticker, colorScheme: colors)
}
/* … */
}
Once the type runs concurrently, the ordinary rules return: the async let pair shares self, and in Apple’s version the struct stored a non-Sendable helper class, which the compiler reported as soon as the two tasks shared it. Apple’s fix was to create the helper inside the function rather than store it. If state genuinely must be shared, that is the point at which you write an actor, as in our camera capture article, where one actor owns the AVCaptureSession.
Error 3: a protocol you declared
Protocols get the default too. A protocol with no annotation is inferred @MainActor, and a type that conforms to it in its declaration inherits that isolation, including a type in another module whose own default is nonisolated. The compiler changelog also notes that, in released compilers, an actor conforming to such a protocol picks up main-actor isolation on its static members and initialisers, which a change on main will stop. If a protocol is implemented by background workers or actors, say so:
nonisolated protocol ImageSource {
func image(for id: String) async throws -> Data
}
An order that works
- Be in the Swift 6 language mode first, so that the five features really do reduce to two and the data-race diagnostics are already errors you have dealt with.
- Turn on Approachable Concurrency for all targets, or enable
NonisolatedNonsendingByDefaultin migration mode and review each@concurrentit adds. Profile the paths that moved. - Set Default Actor Isolation to
MainActoron the app target only. Fix the three errors above:nonisolatedon data types,nonisolatedplus@concurrenton workers,nonisolatedon the protocols they implement. - Leave data and networking packages at
nonisolated. Apple’s advice for library code is to provide nonisolated APIs and let the caller decide whether to offload. - Delete the
@MainActorannotations the default makes redundant.
A future Swift release adds file-level defaults (SE-0478), so a file can start with default nonisolated instead of annotating each type. It is in the changelog under the unreleased version, not Swift 6.4.
If you want help moving an app to Swift 6 and the new defaults, see our iOS app development service.