Swift Concurrency
This skill covers two jobs: fixing concurrency problems in code you're changing, and reviewing concurrency code you didn't write for correctness. Use Quick Fix Mode / When Quick Fixes Fail for the former, Review Mode for the latter. Both share the same reference files below.
Fast Path
Before proposing a fix:
- Analyze
Package.swift or .pbxproj to determine Swift language mode, strict concurrency level, default isolation, and upcoming features. Do this always, not only for migration work.
- Capture the exact diagnostic and offending symbol.
- Determine the isolation boundary:
@MainActor, custom actor, actor instance isolation, or nonisolated.
- Confirm whether the code is UI-bound or intended to run off the main actor. When spawning unstructured tasks, inspect the synchronous prefix (everything before the first
await): start on @MainActor only when that prefix truly needs main-actor access; otherwise use Task { @concurrent in ... } and hop back with MainActor.run only after the suspension. A trivial non-main line (for example, print) followed by main-actor work in the same prefix is not a reason to use @concurrent. For delayed retries, timers, and backoff tasks, separate the waiting from the UI mutation. The sleep often belongs off the main actor even when the final state update belongs on it.
Project settings that change concurrency behavior:
| Setting |
SwiftPM (Package.swift) |
Xcode (.pbxproj) |
| Language mode |
swiftLanguageVersions or -swift-version (// swift-tools-version: is not a reliable proxy) |
Swift Language Version |
| Strict concurrency |
.enableExperimentalFeature("StrictConcurrency=targeted") |
SWIFT_STRICT_CONCURRENCY |
| Default isolation |
.defaultIsolation(MainActor.self) |
SWIFT_DEFAULT_ACTOR_ISOLATION |
| Upcoming features |
.enableUpcomingFeature("NonisolatedNonsendingByDefault") |
SWIFT_UPCOMING_FEATURE_* |
| Approachable Concurrency |
N/A (use individual upcoming features) |
SWIFT_APPROACHABLE_CONCURRENCY |
Xcode 26 note: New projects created in Xcode 26 will often start with SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor and SWIFT_APPROACHABLE_CONCURRENCY = YES enabled by default. Treat these as likely defaults for newly created projects, not as confirmed settings.
If any of these are unknown, ask the developer to confirm them before giving migration-sensitive guidance. Do not guess, even for new Xcode 26 projects. If code spans multiple targets or packages, compare their concurrency build settings before assuming behavior should match across them — a fix that's correct in one module can be wrong in a neighbor with a different default isolation.
Guardrails:
- Do not recommend
@MainActor as a blanket fix. Justify why the code is truly UI-bound.
- Prefer structured concurrency over unstructured tasks. Use
Task.detached only with a clear reason.
- Prefer async/await over a closure-based variant whenever an API offers both.
- GCD (
DispatchQueue, locks, serial queues) is still a legitimate tool in low-level libraries, framework interop, and performance-critical synchronous sections — don't flag it just because it's not async/await. See references/migration.md for when to actually convert it.
- If recommending
@preconcurrency, @unchecked Sendable, or nonisolated(unsafe), require a documented safety invariant and a follow-up removal plan. @unchecked Sendable's only broadly legitimate use is a type with its own internal locking that's provably thread-safe — check whether Swift 6 region-based isolation already makes it unnecessary before reaching for it.
- Do not introduce third-party concurrency frameworks without asking first.
- Optimize for the smallest safe change. Do not refactor unrelated architecture during migration.
- Course references are for deeper learning only. Use them sparingly and only when they clearly help answer the developer's question.
Quick Fix Mode
Use Quick Fix Mode when all of these are true:
- The issue is localized to one file or one type.
- The isolation boundary is clear.
- The fix can be explained in 1-2 behavior-preserving steps.
Skip Quick Fix Mode when any of these are true:
- Build settings or default isolation are unknown.
- The issue crosses module boundaries or changes public API behavior.
- The likely fix depends on unsafe escape hatches.
For open-ended "review this code" requests rather than a specific fix, use Review Mode below instead.
Common Diagnostics
| Diagnostic |
First check |
Smallest safe fix |
Escalate to |
Main actor-isolated ... cannot be used from a nonisolated context |
Is this truly UI-bound? |
Isolate the caller to @MainActor or use await MainActor.run { ... } only when main-actor ownership is correct. |
references/actors.md, references/threading.md |
Actor-isolated type does not conform to protocol |
Must the requirement run on the actor? |
Prefer isolated conformance (e.g., extension Foo: @MainActor SomeProtocol); use nonisolated only for truly nonisolated requirements. |
references/actors.md |
Sending value of non-Sendable type ... risks causing data races |
What isolation boundary is being crossed? |
Keep access inside one actor, or convert the transferred value to an immutable/value type. |
references/sendable.md, references/diagnostics.md |
Static property 'x' is not concurrency-safe |
Is it UI state, a true constant, or genuinely unsynchronized? |
@MainActor annotation, Sendable conformance if truly immutable, or nonisolated(unsafe) as a last resort. |
references/sendable.md, references/diagnostics.md |
SwiftLint async_without_await |
Is async actually required by protocol, override, or @concurrent? |
Remove async, or use a narrow suppression with rationale. Never add fake awaits. |
references/linting.md |
wait(...) is unavailable from asynchronous contexts |
Is this legacy XCTest async waiting? |
Replace with await fulfillment(of:) or Swift Testing equivalents. |
references/testing.md |
| Core Data concurrency warnings |
Are NSManagedObject instances crossing contexts or actors? |
Pass NSManagedObjectID or map to a Sendable value type. |
references/core-data.md |
Thread.current unavailable from asynchronous contexts |
Are you debugging by thread instead of isolation? |
Reason in terms of isolation and use Instruments/debugger instead. |
references/threading.md |
| SwiftLint concurrency-related warnings |
Which specific lint rule triggered? |
Use references/linting.md for rule intent and preferred fixes; avoid dummy awaits. |
references/linting.md |
... cannot satisfy conformance requirement for a 'Sendable' type parameter (SendableMetatype) |
Does the conformance carry global-actor isolation? |
Remove actor isolation from the conformance, or avoid passing the metatype across isolation boundaries. See SendableMetatype section in references/actors.md. |
references/actors.md |
For compiler-error messages not in this table, or for an ordered "try these fixes in order" walkthrough, see references/diagnostics.md.
When Quick Fixes Fail
- Gather project settings if not already confirmed.
- Re-evaluate which isolation boundaries the type crosses.
- Route to the matching reference file for a deeper fix.
- If the fix may change behavior, document the invariant and add verification steps.
Smallest Safe Fixes
Prefer changes that preserve behavior while satisfying data-race safety:
- UI-bound state: isolate the type or member to
@MainActor.
- Shared mutable state: move it behind an
actor, or use @MainActor only if the state is UI-owned.
- Background work: when work must hop off caller isolation, use an
async API marked @concurrent; when work can safely inherit caller isolation, use nonisolated without @concurrent. When spawning a Task, match entry isolation to its synchronous prefix. If nothing before the first await needs the main actor, use Task { @concurrent in ... } and hop back via await MainActor.run { ... } for the UI update. If the prefix mixes a trivial non-main statement with main-actor work, keep the inherited @MainActor start—splitting the cheap line off-main is not worth an extra hop.
- Sendability issues: prefer immutable values and explicit boundaries over
@unchecked Sendable.
Concurrency Tool Selection
| Need |
Tool |
Key Guidance |
| Single async operation |
async/await |
Default choice for sequential async work |
| Fixed parallel operations |
async let |
Known count at compile time; auto-cancelled on throw |
| Dynamic parallel operations |
withTaskGroup |
Unknown count; structured — cancels children on scope exit |
| Sync → async bridge |
Task { } |
Inherits actor context; use Task.detached only with documented reason |
| Shared mutable state |
actor |
Prefer over locks/queues; keep isolated sections small |
| UI-bound state |
@MainActor |
Only for truly UI-related code; justify isolation |
Common Scenarios
Network request with UI update
Task { @concurrent in
let data = try await fetchData()
await MainActor.run { self.updateUI(with: data) }
}
Processing array items in parallel
await withTaskGroup(of: ProcessedItem.self) { group in
for item in items {
group.addTask { await process(item) }
}
for await result in group {
results.append(result)
}
}
Task entry isolation
Match a Task's entry isolation to its synchronous prefix (everything from { to the first await).
- If anything in that prefix needs
@MainActor, keep the inherited @MainActor start.
- If nothing in that prefix needs
@MainActor, prefer Task { @concurrent in ... } and hop back only for UI-owned mutation.
// ❌ Synchronous prefix is empty; first work hops away
Task {
await hopToOtherIsolationDomain()
}
// ❌ Synchronous prefix is only `print` (trivial, non-main); first await hops away
Task {
print("Also not main-thread-bound")
await hopToOtherIsolationDomain()
}
// ✅ Start off the main actor, hop back only for UI work
Task { @concurrent in
await hopToOtherIsolationDomain()
await MainActor.run { updateUI() }
}
// ✅ Synchronous prefix DOES contain main-actor work — keep inheritance
Task {
print("debug") // trivial, non-main — rides along
self.isLoading = true // needs @MainActor, before any await
await fetchData()
}
Swift 6 Migration Quick Guide
Key changes in Swift 6:
- Strict concurrency checking enabled by default
- Complete data-race safety at compile time
- Sendable requirements enforced on boundaries
- Isolation checking for all async boundaries
Migration Validation Loop
Apply this cycle for each migration change:
- Build — Run
swift build or Xcode build to surface new diagnostics
- Fix — Address one category of error at a time (e.g., all Sendable issues first)
- Rebuild — Confirm the fix compiles cleanly before moving on
- Test — Run the test suite to catch regressions (
swift test or Cmd+U)
- Only proceed to the next file/module when all diagnostics are resolved
If a fix introduces new warnings, resolve them before continuing. Never batch multiple unrelated fixes — keep commits small and reviewable.
For detailed migration steps, see references/migration.md.
Review Mode
Use Review Mode when asked to review, audit, or critique existing concurrency code rather than fix one named diagnostic. Report only genuine problems — do not nitpick or invent issues. If doing a partial review, load only the reference files relevant to what changed.
Review order (skip steps that don't apply):
- Scan for known-dangerous patterns to prioritize what to inspect —
references/hotspots.md.
- Check whether recent Swift 6.2 behavior changes the right answer (default isolation,
@concurrent, isolated conformances) — references/actors.md, references/threading.md.
- Validate actor usage for reentrancy, isolation, and global/static state —
references/actors.md.
- Confirm structured concurrency (task groups) is preferred over unstructured (
Task {}, Task.detached) where appropriate — references/tasks.md.
- Verify cancellation is propagated and checked correctly —
references/tasks.md.
- Validate async stream, sequence, and continuation usage —
references/async-sequences.md.
- Check bridging code between sync and async worlds (continuations,
@unchecked Sendable) — references/sendable.md, references/migration.md.
- Review any legacy-concurrency migrations (GCD, delegates, Combine) —
references/migration.md.
- Cross-check against common failure modes —
references/bug-patterns.md.
- If the project has strict-concurrency errors, map diagnostics to fixes —
references/diagnostics.md.
- If reviewing tests, check async test patterns —
references/testing.md.
Review-specific guardrails, in addition to the Fast Path guardrails above:
- Target Swift 6.2+ with strict concurrency checking unless the project's settings say otherwise (see Fast Path step 1).
- If an API offers both
async/await and closure-based variants, flag call sites still using the closure form.
- Don't flag GCD, locks, or
Task.detached on sight — check the context first (see Fast Path guardrails).
Review Output Format
Organize findings by file. For each issue: state the file and line(s), name the rule being violated, and show a brief before/after fix. Skip files with no issues. End with a prioritized summary — highest-impact fix first.
### DataLoader.swift
**Line 18: Actor reentrancy — state may have changed across the `await`.**
// Before
actor Cache {
var items: [String: Data] = [:]
func fetch(_ key: String) async throws -> Data {
if items[key] == nil { items[key] = try await download(key) }
return items[key]!
}
}
// After
actor Cache {
var items: [String: Data] = [:]
func fetch(_ key: String) async throws -> Data {
if let existing = items[key] { return existing }
let data = try await download(key)
items[key] = data
return data
}
}
### Summary
1. **Correctness (high):** Actor reentrancy bug on line 18 may cause duplicate downloads and a force-unwrap crash.
Reference Router
Open the smallest reference that matches the question:
- Foundations
references/async-await-basics.md — async/await syntax, execution order, async let, URLSession patterns
references/tasks.md — Task lifecycle, cancellation, withTaskCancellationHandler, priorities, task groups, structured vs unstructured, Task.immediate, task naming
references/actors.md — Actor isolation, @MainActor, global actors, reentrancy (incl. in-flight-task dedup), custom executors, Mutex
references/sendable.md — Sendable conformance, value/reference types, @unchecked, region isolation
references/threading.md — Execution model, suspension points, Swift 6.2 isolation behavior
- Streams
references/async-sequences.md — AsyncSequence, AsyncStream (incl. makeStream(of:)), when to use vs regular async methods
references/async-algorithms.md — Debounce, throttle, merge, combineLatest, channels, timers
- Applied topics
references/testing.md — Swift Testing first, XCTest fallback, leak checks, race detection with Thread Sanitizer
references/performance.md — Profiling with Instruments, reducing suspension points, execution strategies
references/memory-management.md — Retain cycles in tasks, memory safety patterns
references/core-data.md — NSManagedObject sendability, custom executors, isolation conflicts
- Migration and tooling
references/migration.md — Swift 6 migration strategy, closure/delegate-to-async conversion, continuation resume rules, @preconcurrency, GCD and FRP migration
references/linting.md — Concurrency-focused lint rules and SwiftLint async_without_await
- Review
references/hotspots.md — Grep targets for code review: known-dangerous patterns and what to check for each
references/bug-patterns.md — Common concurrency failure modes and their fixes, for fast review scanning
references/diagnostics.md — Strict-concurrency compiler errors mapped to ordered, "try this first" fixes
- Glossary
references/glossary.md — Quick definitions of core concurrency terms
Verification Checklist
When changing concurrency code:
- Re-check build settings before interpreting diagnostics.
- Build and clear one category of errors before moving on. Do not batch unrelated fixes into the same change.
- Run tests, especially actor-, lifetime-, and cancellation-sensitive tests.
- Use Instruments for performance claims instead of guessing.
- Verify deallocation and cancellation behavior for long-lived tasks.
- Check
Task.isCancelled in long-running operations.
- Never use semaphores or ad hoc locking in async contexts when actor isolation or
Mutex would express ownership more safely.
Note: This skill is based on the comprehensive Swift Concurrency Course by Antoine van der Lee, and incorporates review methodology from the Swift Concurrency Agent Skill by Paul Hudson.
1---2name: swift-concurrency3description: Load this whenever Swift concurrency code is being written, fixed, migrated, or reviewed. Diagnoses and fixes Swift Concurrency issues (tasks, actors, @MainActor, Sendable, data races, thread safety, concurrency-related compiler and linter warnings), refactors callback-based code to async/await, guides Swift 6/6.2 migration, AND reviews Swift code for concurrency correctness, modern API usage, and async/await pitfalls. If the code touches `async`, `await`, `actor`, `Task`, `Sendable`, or a strict-concurrency diagnostic, check here first — don't guess at isolation rules from memory.4---5# Swift Concurrency67This skill covers two jobs: **fixing** concurrency problems in code you're changing, and **reviewing** concurrency code you didn't write for correctness. Use Quick Fix Mode / When Quick Fixes Fail for the former, Review Mode for the latter. Both share the same reference files below.89## Fast Path1011Before proposing a fix:12131. Analyze `Package.swift` or `.pbxproj` to determine Swift language mode, strict concurrency level, default isolation, and upcoming features. Do this always, not only for migration work.142. Capture the exact diagnostic and offending symbol.153. Determine the isolation boundary: `@MainActor`, custom actor, actor instance isolation, or `nonisolated`.164. Confirm whether the code is UI-bound or intended to run off the main actor. When spawning unstructured tasks, inspect the synchronous prefix (everything before the first `await`): start on `@MainActor` only when that prefix truly needs main-actor access; otherwise use `Task { @concurrent in ... }` and hop back with `MainActor.run` only after the suspension. A trivial non-main line (for example, `print`) followed by main-actor work in the same prefix is not a reason to use `@concurrent`. For delayed retries, timers, and backoff tasks, separate the waiting from the UI mutation. The sleep often belongs off the main actor even when the final state update belongs on it.1718Project settings that change concurrency behavior:1920| Setting | SwiftPM (`Package.swift`) | Xcode (`.pbxproj`) |21|---|---|---|22| Language mode | `swiftLanguageVersions` or `-swift-version` (`// swift-tools-version:` is not a reliable proxy) | Swift Language Version |23| Strict concurrency | `.enableExperimentalFeature("StrictConcurrency=targeted")` | `SWIFT_STRICT_CONCURRENCY` |24| Default isolation | `.defaultIsolation(MainActor.self)` | `SWIFT_DEFAULT_ACTOR_ISOLATION` |25| Upcoming features | `.enableUpcomingFeature("NonisolatedNonsendingByDefault")` | `SWIFT_UPCOMING_FEATURE_*` |26| Approachable Concurrency | N/A (use individual upcoming features) | `SWIFT_APPROACHABLE_CONCURRENCY` |2728> **Xcode 26 note**: New projects created in Xcode 26 will often start with `SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor` and `SWIFT_APPROACHABLE_CONCURRENCY = YES` enabled by default. Treat these as likely defaults for newly created projects, not as confirmed settings.2930If any of these are unknown, ask the developer to confirm them before giving migration-sensitive guidance. Do not guess, even for new Xcode 26 projects. If code spans multiple targets or packages, compare their concurrency build settings before assuming behavior should match across them — a fix that's correct in one module can be wrong in a neighbor with a different default isolation.3132Guardrails:3334- Do not recommend `@MainActor` as a blanket fix. Justify why the code is truly UI-bound.35- Prefer structured concurrency over unstructured tasks. Use `Task.detached` only with a clear reason.36- Prefer async/await over a closure-based variant whenever an API offers both.37- GCD (`DispatchQueue`, locks, serial queues) is still a legitimate tool in low-level libraries, framework interop, and performance-critical synchronous sections — don't flag it just because it's not `async`/`await`. See `references/migration.md` for when to actually convert it.38- If recommending `@preconcurrency`, `@unchecked Sendable`, or `nonisolated(unsafe)`, require a documented safety invariant and a follow-up removal plan. `@unchecked Sendable`'s only broadly legitimate use is a type with its own internal locking that's provably thread-safe — check whether Swift 6 region-based isolation already makes it unnecessary before reaching for it.39- Do not introduce third-party concurrency frameworks without asking first.40- Optimize for the smallest safe change. Do not refactor unrelated architecture during migration.41- Course references are for deeper learning only. Use them sparingly and only when they clearly help answer the developer's question.4243## Quick Fix Mode4445Use Quick Fix Mode when all of these are true:4647- The issue is localized to one file or one type.48- The isolation boundary is clear.49- The fix can be explained in 1-2 behavior-preserving steps.5051Skip Quick Fix Mode when any of these are true:5253- Build settings or default isolation are unknown.54- The issue crosses module boundaries or changes public API behavior.55- The likely fix depends on unsafe escape hatches.5657For open-ended "review this code" requests rather than a specific fix, use Review Mode below instead.5859## Common Diagnostics6061| Diagnostic | First check | Smallest safe fix | Escalate to |62|---|---|---|---|63| `Main actor-isolated ... cannot be used from a nonisolated context` | Is this truly UI-bound? | Isolate the caller to `@MainActor` or use `await MainActor.run { ... }` only when main-actor ownership is correct. | `references/actors.md`, `references/threading.md` |64| `Actor-isolated type does not conform to protocol` | Must the requirement run on the actor? | Prefer isolated conformance (e.g., `extension Foo: @MainActor SomeProtocol`); use `nonisolated` only for truly nonisolated requirements. | `references/actors.md` |65| `Sending value of non-Sendable type ... risks causing data races` | What isolation boundary is being crossed? | Keep access inside one actor, or convert the transferred value to an immutable/value type. | `references/sendable.md`, `references/diagnostics.md` |66| `Static property 'x' is not concurrency-safe` | Is it UI state, a true constant, or genuinely unsynchronized? | `@MainActor` annotation, `Sendable` conformance if truly immutable, or `nonisolated(unsafe)` as a last resort. | `references/sendable.md`, `references/diagnostics.md` |67| `SwiftLint async_without_await` | Is `async` actually required by protocol, override, or `@concurrent`? | Remove `async`, or use a narrow suppression with rationale. Never add fake awaits. | `references/linting.md` |68| `wait(...) is unavailable from asynchronous contexts` | Is this legacy XCTest async waiting? | Replace with `await fulfillment(of:)` or Swift Testing equivalents. | `references/testing.md` |69| Core Data concurrency warnings | Are `NSManagedObject` instances crossing contexts or actors? | Pass `NSManagedObjectID` or map to a Sendable value type. | `references/core-data.md` |70| `Thread.current` unavailable from asynchronous contexts | Are you debugging by thread instead of isolation? | Reason in terms of isolation and use Instruments/debugger instead. | `references/threading.md` |71| SwiftLint concurrency-related warnings | Which specific lint rule triggered? | Use `references/linting.md` for rule intent and preferred fixes; avoid dummy awaits. | `references/linting.md` |72| `... cannot satisfy conformance requirement for a 'Sendable' type parameter` (`SendableMetatype`) | Does the conformance carry global-actor isolation? | Remove actor isolation from the conformance, or avoid passing the metatype across isolation boundaries. See `SendableMetatype` section in `references/actors.md`. | `references/actors.md` |7374For compiler-error messages not in this table, or for an ordered "try these fixes in order" walkthrough, see `references/diagnostics.md`.7576## When Quick Fixes Fail77781. Gather project settings if not already confirmed.792. Re-evaluate which isolation boundaries the type crosses.803. Route to the matching reference file for a deeper fix.814. If the fix may change behavior, document the invariant and add verification steps.8283## Smallest Safe Fixes8485Prefer changes that preserve behavior while satisfying data-race safety:8687- **UI-bound state**: isolate the type or member to `@MainActor`.88- **Shared mutable state**: move it behind an `actor`, or use `@MainActor` only if the state is UI-owned.89- **Background work**: when work must hop off caller isolation, use an `async` API marked `@concurrent`; when work can safely inherit caller isolation, use `nonisolated` without `@concurrent`. When spawning a `Task`, match entry isolation to its synchronous prefix. If nothing before the first `await` needs the main actor, use `Task { @concurrent in ... }` and hop back via `await MainActor.run { ... }` for the UI update. If the prefix mixes a trivial non-main statement with main-actor work, keep the inherited `@MainActor` start—splitting the cheap line off-main is not worth an extra hop.90- **Sendability issues**: prefer immutable values and explicit boundaries over `@unchecked Sendable`.9192## Concurrency Tool Selection9394| Need | Tool | Key Guidance |95|---|---|---|96| Single async operation | `async/await` | Default choice for sequential async work |97| Fixed parallel operations | `async let` | Known count at compile time; auto-cancelled on throw |98| Dynamic parallel operations | `withTaskGroup` | Unknown count; structured — cancels children on scope exit |99| Sync → async bridge | `Task { }` | Inherits actor context; use `Task.detached` only with documented reason |100| Shared mutable state | `actor` | Prefer over locks/queues; keep isolated sections small |101| UI-bound state | `@MainActor` | Only for truly UI-related code; justify isolation |102103### Common Scenarios104105**Network request with UI update**106```swift107Task { @concurrent in108 let data = try await fetchData()109 await MainActor.run { self.updateUI(with: data) }110}111```112113**Processing array items in parallel**114```swift115await withTaskGroup(of: ProcessedItem.self) { group in116 for item in items {117 group.addTask { await process(item) }118 }119 for await result in group {120 results.append(result)121 }122}123```124125126## Task entry isolation127128Match a `Task`'s entry isolation to its synchronous prefix (everything from `{` to the first `await`).129130- If anything in that prefix needs `@MainActor`, keep the inherited `@MainActor` start.131- If nothing in that prefix needs `@MainActor`, prefer `Task { @concurrent in ... }` and hop back only for UI-owned mutation.132133```swift134// ❌ Synchronous prefix is empty; first work hops away135Task {136 await hopToOtherIsolationDomain()137}138139// ❌ Synchronous prefix is only `print` (trivial, non-main); first await hops away140Task {141 print("Also not main-thread-bound")142 await hopToOtherIsolationDomain()143}144145// ✅ Start off the main actor, hop back only for UI work146Task { @concurrent in147 await hopToOtherIsolationDomain()148 await MainActor.run { updateUI() }149}150151// ✅ Synchronous prefix DOES contain main-actor work — keep inheritance152Task {153 print("debug") // trivial, non-main — rides along154 self.isLoading = true // needs @MainActor, before any await155 await fetchData()156}157```158159## Swift 6 Migration Quick Guide160161Key changes in Swift 6:162- **Strict concurrency checking** enabled by default163- **Complete data-race safety** at compile time164- **Sendable requirements** enforced on boundaries165- **Isolation checking** for all async boundaries166167### Migration Validation Loop168169Apply this cycle for each migration change:1701711. **Build** — Run `swift build` or Xcode build to surface new diagnostics1722. **Fix** — Address one category of error at a time (e.g., all Sendable issues first)1733. **Rebuild** — Confirm the fix compiles cleanly before moving on1744. **Test** — Run the test suite to catch regressions (`swift test` or Cmd+U)1755. **Only proceed** to the next file/module when all diagnostics are resolved176177If a fix introduces new warnings, resolve them before continuing. Never batch multiple unrelated fixes — keep commits small and reviewable.178179For detailed migration steps, see `references/migration.md`.180181## Review Mode182183Use Review Mode when asked to review, audit, or critique existing concurrency code rather than fix one named diagnostic. **Report only genuine problems — do not nitpick or invent issues.** If doing a partial review, load only the reference files relevant to what changed.184185Review order (skip steps that don't apply):1861871. Scan for known-dangerous patterns to prioritize what to inspect — `references/hotspots.md`.1882. Check whether recent Swift 6.2 behavior changes the right answer (default isolation, `@concurrent`, isolated conformances) — `references/actors.md`, `references/threading.md`.1893. Validate actor usage for reentrancy, isolation, and global/static state — `references/actors.md`.1904. Confirm structured concurrency (task groups) is preferred over unstructured (`Task {}`, `Task.detached`) where appropriate — `references/tasks.md`.1915. Verify cancellation is propagated and checked correctly — `references/tasks.md`.1926. Validate async stream, sequence, and continuation usage — `references/async-sequences.md`.1937. Check bridging code between sync and async worlds (continuations, `@unchecked Sendable`) — `references/sendable.md`, `references/migration.md`.1948. Review any legacy-concurrency migrations (GCD, delegates, Combine) — `references/migration.md`.1959. Cross-check against common failure modes — `references/bug-patterns.md`.19610. If the project has strict-concurrency errors, map diagnostics to fixes — `references/diagnostics.md`.19711. If reviewing tests, check async test patterns — `references/testing.md`.198199Review-specific guardrails, in addition to the Fast Path guardrails above:200201- Target Swift 6.2+ with strict concurrency checking unless the project's settings say otherwise (see Fast Path step 1).202- If an API offers both `async`/`await` and closure-based variants, flag call sites still using the closure form.203- Don't flag GCD, locks, or `Task.detached` on sight — check the context first (see Fast Path guardrails).204205### Review Output Format206207Organize findings by file. For each issue: state the file and line(s), name the rule being violated, and show a brief before/after fix. Skip files with no issues. End with a prioritized summary — highest-impact fix first.208209```210### DataLoader.swift211212**Line 18: Actor reentrancy — state may have changed across the `await`.**213214// Before215actor Cache {216 var items: [String: Data] = [:]217 func fetch(_ key: String) async throws -> Data {218 if items[key] == nil { items[key] = try await download(key) }219 return items[key]!220 }221}222223// After224actor Cache {225 var items: [String: Data] = [:]226 func fetch(_ key: String) async throws -> Data {227 if let existing = items[key] { return existing }228 let data = try await download(key)229 items[key] = data230 return data231 }232}233234### Summary2351. **Correctness (high):** Actor reentrancy bug on line 18 may cause duplicate downloads and a force-unwrap crash.236```237238## Reference Router239240Open the smallest reference that matches the question:241242- Foundations243 - `references/async-await-basics.md` — async/await syntax, execution order, async let, URLSession patterns244 - `references/tasks.md` — Task lifecycle, cancellation, `withTaskCancellationHandler`, priorities, task groups, structured vs unstructured, `Task.immediate`, task naming245 - `references/actors.md` — Actor isolation, @MainActor, global actors, reentrancy (incl. in-flight-task dedup), custom executors, Mutex246 - `references/sendable.md` — Sendable conformance, value/reference types, @unchecked, region isolation247 - `references/threading.md` — Execution model, suspension points, Swift 6.2 isolation behavior248- Streams249 - `references/async-sequences.md` — AsyncSequence, AsyncStream (incl. `makeStream(of:)`), when to use vs regular async methods250 - `references/async-algorithms.md` — Debounce, throttle, merge, combineLatest, channels, timers251- Applied topics252 - `references/testing.md` — Swift Testing first, XCTest fallback, leak checks, race detection with Thread Sanitizer253 - `references/performance.md` — Profiling with Instruments, reducing suspension points, execution strategies254 - `references/memory-management.md` — Retain cycles in tasks, memory safety patterns255 - `references/core-data.md` — NSManagedObject sendability, custom executors, isolation conflicts256- Migration and tooling257 - `references/migration.md` — Swift 6 migration strategy, closure/delegate-to-async conversion, continuation resume rules, @preconcurrency, GCD and FRP migration258 - `references/linting.md` — Concurrency-focused lint rules and SwiftLint `async_without_await`259- Review260 - `references/hotspots.md` — Grep targets for code review: known-dangerous patterns and what to check for each261 - `references/bug-patterns.md` — Common concurrency failure modes and their fixes, for fast review scanning262 - `references/diagnostics.md` — Strict-concurrency compiler errors mapped to ordered, "try this first" fixes263- Glossary264 - `references/glossary.md` — Quick definitions of core concurrency terms265266## Verification Checklist267268When changing concurrency code:2692701. Re-check build settings before interpreting diagnostics.2712. Build and clear one category of errors before moving on. Do not batch unrelated fixes into the same change.2723. Run tests, especially actor-, lifetime-, and cancellation-sensitive tests.2734. Use Instruments for performance claims instead of guessing.2745. Verify deallocation and cancellation behavior for long-lived tasks.2756. Check `Task.isCancelled` in long-running operations.2767. Never use semaphores or ad hoc locking in async contexts when actor isolation or `Mutex` would express ownership more safely.277278---279280**Note**: This skill is based on the comprehensive [Swift Concurrency Course](https://www.swiftconcurrencycourse.com?utm_source=github&utm_medium=agent-skill&utm_campaign=skill-footer) by Antoine van der Lee, and incorporates review methodology from the [Swift Concurrency Agent Skill](https://github.com/twostraws/Swift-Concurrency-Agent-Skill) by Paul Hudson.