← ClaudeAtlas

swift-concurrency-6-2listed

Use when writing or migrating Swift 6.2 concurrency code. Covers SE-0461/SE-0466 semantics (async stays on the caller, MainActor default inference), @concurrent offloading, isolated conformances, and Xcode 26 build settings.
Mixard/fable-pack · ★ 1 · AI & Automation · score 74
Install: claude install-skill Mixard/fable-pack
# Swift 6.2 Approachable Concurrency Swift 6.2 changes the default execution model: code is single-threaded by default and concurrency is introduced explicitly. Two proposals define the version-specific behavior: - **SE-0461 (NonisolatedNonsendingByDefault)**: nonisolated async functions run on the caller's actor instead of being implicitly offloaded to the concurrent pool. - **SE-0466 (MainActor default isolation)**: an opt-in mode where declarations in a module are inferred `@MainActor` unless marked otherwise. Recommended for apps, scripts, and other executable targets. Both are opt-in build settings; without them, pre-6.2 offloading semantics apply. ## Async stays on the calling actor In Swift 6.1 and earlier, async functions could be implicitly offloaded to background threads, producing data-race errors in seemingly safe code: ```swift @MainActor final class StickerModel { let photoProcessor = PhotoProcessor() func extractSticker(_ item: PhotosPickerItem) async throws -> Sticker? { guard let data = try await item.loadTransferable(type: Data.self) else { return nil } // Swift 6.1: error — "Sending 'self.photoProcessor' risks causing data races" // Swift 6.2: OK — the async call stays on MainActor return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier) } } ``` Consequence: do not assume async code runs in the background. Under 6.2 defaults it runs wherever the caller is isolated, unless marked `@