rshankras/claude-code-apple-skills/concurrency
Claude Code and agent skill by rshankras/claude-code-apple-skills
- community
Checking that the SKILL.md file is still in the repository.
Swift 6.2 concurrency updates including default MainActor inference, @concurrent for background work, isolated conformances, and approachable concurrency migration. Use when adopting Swift 6.2 concurrency features or fixing data-race errors.
Install
npx vskill@latest install rshankras/claude-code-apple-skills/concurrencySKILL.md
Swift 6.2 Concurrency Updates
Swift 6.2 introduces "Approachable Concurrency" -- a set of changes that make strict concurrency dramatically easier to adopt. Code runs on @MainActor by default, async functions stay on the calling actor, and you explicitly request background execution with @concurrent.
This skill covers only the Swift 6.2 specific changes. For general concurrency patterns (actors, TaskGroup, AsyncSequence, Sendable, cancellation), see the swift/concurrency-patterns skill.
When This Skill Activates
- User is adopting Swift 6.2 concurrency features
- User asks about default MainActor inference or the "infer main actor" build setting
- User encounters data-race errors that Swift 6.2 resolves
- User asks about
@concurrent, isolated conformances, or approachable concurrency - User wants to migrate from Swift 6.0/6.1 strict concurrency to 6.2
- User asks how async functions behave differently in Swift 6.2
- User needs to offload CPU-intensive work to a background thread in Swift 6.2
What Changed in Swift 6.2 vs Before
Swift 6.2 Changes at a Glance
| Feature | Before (6.0/6.1) | After (6.2) | |
|---|---|---|---|
| Default isolation | Nothing inferred; manual @MainActor everywhere | Opt-in mode infers @MainActor on everything | |
| Async function execution | Hops to generic concurrent executor | Stays on calling actor | |
@MainActor type conforming to protocol | Compiler error for non-isolated protocols | Isolated conformances: @MainActor Protocol | |
| Background execution | Task.detached or manual nonisolated functions | @concurrent attribute | |
| Global/static mutable state | Required @MainActor annotation or Sendable | Default MainActor mode handles it automatically |
1. Async Functions Stay on the Calling Actor
In Swift 6.2, async functions without specific actor isolation stay on whatever actor called them, instead of hopping to the generic concurrent executor as in 6.0/6.1 -- eliminating a common source of data-race errors with no code changes required.
2. Default MainActor Inference Mode
An opt-in build setting that makes all code implicitly @MainActor unless explicitly opted out with nonisolated.
Enabling It
Xcode: Build Settings > Swift Compiler - Concurrency > "Default Actor Isolation" > "MainActor"
Swift Package Manager:
With this enabled, app-level types no longer need explicit @MainActor annotations -- including global/static mutable state, which otherwise needs an explicit @MainActor static let ....
When to Use Default MainActor Inference
| Target Type | Recommended? | Reason | |
|---|---|---|---|
| App target | Yes | Apps are UI-driven; most code belongs on MainActor | |
| Script / executable | Yes | Scripts are sequential; MainActor default is natural | |
| Library / framework | No | Libraries must not impose actor isolation on consumers | |
| Package plugin | No | Same reasoning as libraries |
Opting Out with nonisolated
When a type or function genuinely needs to run off the main actor, mark it nonisolated:
3. Isolated Conformances
Isolated conformances let a @MainActor type conform to a protocol that does not require actor isolation, using extension Type: @MainActor ProtocolName. Before Swift 6.2, this produced a compiler error about the main actor-isolated conformance crossing an isolation boundary.
The conformance can only be used from a context that shares the same isolation domain:
4. @concurrent -- Explicit Background Execution
@concurrent explicitly offloads a function to the background thread pool, replacing the pattern of using Task.detached for compute-intensive operations.
Steps to Offload Work
- Make the containing type
nonisolated(for structs/classes; actors are already isolated) - Add
@concurrentto the function - Make the function
async - Callers use
await
@concurrent vs Task.detached vs actor
| Mechanism | Use Case | Structured? | |
|---|---|---|---|
@concurrent | Single function that must run on background thread | Yes (inherits task context) | |
Task.detached | Fire-and-forget background work, no structured parent | No | |
actor | Shared mutable state needing serialized access | N/A (isolation, not scheduling) | |
Task {} | Unstructured task inheriting current actor | No |
When NOT to Use @concurrent
Reserve it for CPU-intensive work, blocking I/O that would freeze the UI, or work measured to be long enough to justify the thread hop -- not trivial functions:
5. Migration Guide
From Swift 6.0/6.1 to Swift 6.2
Step 1: Update to Swift 6.2 toolchain
Ensure your Xcode version supports Swift 6.2 and your project's Swift language version is set to 6.2.
Step 2: Enable default MainActor inference (for app targets)
See "Enabling It" above -- the Xcode build setting or .defaultIsolation(MainActor.self) in swiftSettings.
Step 3: Remove redundant `@MainActor` annotations
With default MainActor inference enabled, explicit @MainActor annotations on app-level types are redundant and can be removed to reduce noise.
Step 4: Replace `Task.detached` with `@concurrent` where appropriate
Mark the offloaded function @concurrent directly instead of wrapping it in a detached task inside a TaskGroup.
Step 5: Fix remaining conformance errors with isolated conformances
Part of migrating to Swift 6.2 involves replacing unsafe @unchecked Sendable workarounds with isolated conformances:
Step 6: Add `nonisolated` to types/functions that must not be on MainActor
With default MainActor inference, anything not explicitly marked nonisolated runs on MainActor. Audit background data processing types, network parsers, file I/O utilities, and computation-heavy algorithms.
Migration Resources
- Xcode build settings: Swift Compiler > Concurrency
- SwiftSettings API for Swift packages
- Official migration tooling: swift.org/migration
- Local captured doc (optional):
~/Downloads/docs/Swift-Concurrency-Updates.md— read if present; skip silently if absent.
Mental Model
Top Mistakes
Mistake 1: Enabling default MainActor inference for a library
Libraries should let consumers choose their own isolation strategy. Only app targets and executables should use default MainActor inference.
Mistake 2: Marking trivial functions @concurrent
Every @concurrent call involves a thread hop. Only use it for genuinely expensive work (see "When NOT to Use @concurrent" above).
Mistake 3: Forgetting nonisolated when default MainActor is enabled
Mistake 4: Using isolated conformances in nonisolated contexts
See "Isolated Conformances" above -- the conformance is only usable from a context that matches its isolation.
Mistake 5: Removing @MainActor annotations without enabling the build setting
Review Checklist
When reviewing code that uses or should use Swift 6.2 concurrency features:
Build Configuration
- [ ] Swift language version is set to 6.2
- [ ] Default MainActor inference is enabled for app/executable targets only (not libraries)
- [ ] Libraries and frameworks do NOT use
.defaultIsolation(MainActor.self)
Actor Isolation
- [ ] Redundant
@MainActorannotations removed (if default MainActor inference is enabled) - [ ]
nonisolatedapplied to types/functions that must run off the main actor - [ ] CPU-intensive work marked
nonisolatedand uses@concurrent - [ ] No heavy computation running implicitly on MainActor
@concurrent Usage
- [ ]
@concurrentonly used for genuinely expensive operations - [ ]
@concurrentfunctions areasync - [ ] Containing type is
nonisolated(for structs/classes) - [ ]
Task.detachedreplaced with@concurrentwhere structured concurrency is preferable
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/swift/concurrency/SKILL.md
Popularity
- Repository stars
- 770
- Repository forks
- 74
- 7-day trend score
- 33
Stars and forks are for the whole GitHub repository, not this skill alone. Refreshed 18 Mar 2026, 7 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/rshankras/claude-code-apple-skills/concurrency)