# swift-concurrency-6-2

> A Claude Code skill from Affaan M's everything-claude-code repo for adopting Swift 6.2's Approachable Concurrency model — single-threaded by default, async stays on the calling actor, @concurrent for explicit background offloading, isolated conformances let MainActor types conform to non-isolated protocols safely. Covers Xcode 26 build settings and migration from 6.0 / 6.1.

**Use case**: Migrate Swift code to 6.2 Approachable Concurrency without losing data-race safety or hand-tuning isolation

**Canonical URL**: https://agentcookbooks.com/skills/swift-concurrency-6-2/

**Topics**: claude-code, skills, ios

**Trigger phrases**: "migrate to Swift 6.2 concurrency", "fix Sending data race error", "isolated conformance for MainActor type"

**Source**: [Affaan M](https://github.com/affaan-m/everything-claude-code/tree/main/skills/swift-concurrency-6-2)

**License**: MIT

---

## What it does

`swift-concurrency-6-2` is the Swift 6.2 concurrency migration skill in [Affaan M's everything-claude-code](https://github.com/affaan-m/everything-claude-code) — see [skills/swift-concurrency-6-2](https://github.com/affaan-m/everything-claude-code/tree/main/skills/swift-concurrency-6-2). Swift 6.2 introduces Approachable Concurrency: code runs single-threaded by default, concurrency is introduced explicitly via `@concurrent`, and the "implicit background offloading" data races that plagued 6.0 / 6.1 go away.

The pre-6.2 problem the skill names directly: an async function on a `@MainActor` type could be implicitly offloaded to a background thread, producing `Sending 'self.photoProcessor' risks causing data races` even in seemingly safe code. Swift 6.2 fixes this — async stays on the calling actor by default. The migration is often as simple as recompiling, but the skill ships the patterns for the non-trivial cases.

Isolated conformances are the second wedge. Pre-6.2, a `@MainActor` type couldn't conform to a plain `Sendable`-aware protocol without crossing into main-actor-isolated code. 6.2 allows `extension StickerModel: @MainActor Exportable {}` — the conformance is statically restricted to the main actor and the compiler enforces it. Non-isolated contexts can't use the conformance, which surfaces architectural mistakes at compile time. The skill also covers global / static state protection (`@MainActor` on the variable), explicit `@concurrent` offloading for CPU-intensive work, and Xcode 26's Approachable Concurrency build setting.

## When to use it

- Migrating a Swift 5.x or 6.0 / 6.1 codebase to 6.2 — the data-race errors fall into a few canonical patterns
- Resolving `Sending 'self.x' risks causing data races` compiler errors on `@MainActor` types
- Designing MainActor-based app architecture where most code runs on main and only specific paths offload to background
- Offloading CPU-intensive work to background threads explicitly via `@concurrent`
- Implementing protocol conformances on `@MainActor`-isolated types (isolated conformances)
- Enabling Approachable Concurrency build settings in Xcode 26

When *not* to reach for it:

- Swift Server-side code that's already structured-concurrency-native — the migration patterns are mostly Apple-platform-shaped
- Pre-Swift-6 codebases — the skill assumes Swift 6 strict concurrency is in scope
- SwiftUI composition patterns specifically — that's `swiftui-patterns`
- Liquid Glass material work — that's `liquid-glass-design`

## Install

From [affaan-m/everything-claude-code](https://github.com/affaan-m/everything-claude-code) at `skills/swift-concurrency-6-2/`. Drop the folder into `~/.claude/skills/swift-concurrency-6-2/`. The skill is markdown patterns; the runtime is Xcode 26+ with the Swift 6.2 toolchain and the Approachable Concurrency build setting enabled.

## What a session looks like

1. **Open the diagnostic.** Compiler error reads `Sending 'self.photoProcessor' risks causing data races`. Skill picks the implicit-background-offload pattern.
2. **Verify the actor isolation.** `StickerModel` is `@MainActor`. The async call to `photoProcessor.extractSticker(...)` was being offloaded in 6.1 — 6.2 keeps it on the main actor.
3. **Confirm the migration is a no-op for this case.** Many 6.1 errors disappear under 6.2 without code changes. The skill is explicit that this is often the path.
4. **Add an isolated conformance.** `StickerModel` needs to conform to `Exportable`. `extension StickerModel: @MainActor Exportable {}` lets the conformance exist while statically restricting use to the main actor.
5. **Verify caller contexts.** Using the conformance from a `@MainActor` `ImageExporter` is OK. Using it from a `nonisolated` context produces a compile error — the type system catches the mistake.
6. **Add `@concurrent` where actual background work is needed.** CPU-heavy image processing gets explicit offloading rather than the implicit kind 6.1 inflicted.
7. **Enable the build setting.** Xcode 26 Approachable Concurrency on for the target.

The discipline that makes it work: trust the compiler. 6.2's wedge is that the type system catches isolation mistakes that 6.1 would silently miscompile or produce data races for at runtime. The migration pattern is usually "let it compile, fix what fails."

## Receipts

_TODO — to be filled in from a real session. Once a real Swift project has been migrated to 6.2, this section will capture: how many of the 6.1 `Sending` errors disappeared on recompile without code changes vs. how many needed actual isolation work, which patterns required `@MainActor Exportable`-style isolated conformances vs. which restructured to a different shape entirely, whether any 6.1 code that compiled cleanly broke under 6.2's stricter rules, and the wall-time cost of the migration vs. the operator's estimate._

## Source and attribution

From [Affaan M's everything-claude-code](https://github.com/affaan-m/everything-claude-code/tree/main/skills/swift-concurrency-6-2) — an MIT-licensed skill collection covering harness construction, agent ops, video, payments, and platform-specific patterns.

License: MIT.