Swift Structured Concurrency Migration Framework
Assess legacy GCD patterns and construct a safe migration framework for Swift 6 structured concurrency.
Use this template when refactoring legacy multithreaded iOS codebases into Swift async/await, actors, and Sendable models. It helps engineering leads eliminate data races while preserving throughput.
Role: Principal iOS Systems Engineer with expertise in Swift 6 concurrency, runtime memory safety, and thread sanitization.
Context
- Target Application: {{app_name}}
- Minimum Supported iOS Version: {{target_ios_version}}
- Legacy Dispatch Strategy: {{legacy_concurrency_pattern}}
- Critical Core Subsystem: {{critical_subsystem}}
- Diagnostics and Tooling: {{thread_safety_tooling}}
- Latency and Throughput Budget: {{performance_budget_ms}}
Task
Produce an actionable, phased migration framework that transitions {{critical_subsystem}} from {{legacy_concurrency_pattern}} to modern Swift structured concurrency without introducing deadlocks, thread explosion, or breaking changes in {{app_name}}.
Method
- Analyze the existing {{legacy_concurrency_pattern}} in {{critical_subsystem}} to identify state mutations across thread boundaries.
- Classify mutable state boundaries into
@MainActor, custom Global Actors, or isolated Actor domains targeting {{target_ios_version}}. - Identify non-isolated class boundaries requiring conversion to value types or explicit
Sendableconformance. - Design continuation bridges (
withCheckedThrowingContinuation) for legacy completion handlers that cannot be rewritten immediately. - Map out structured task trees (
TaskGroupvs unstructuredTask) to maintain deterministic cancellation semantics. - Evaluate actor reentrancy risks across suspension points to prevent intermediate invalid state reads.
- Formulate a verification protocol using {{thread_safety_tooling}} to validate race condition elimination under {{performance_budget_ms}}.
Constraints
- MUST maintain strict compiler complete concurrency checking without disabling runtime safety flags.
- MUST NOT introduce unbounded
Taskcreation inside tight loops that risk thread pool exhaustion. - MUST isolate all UI-bound event handlers and UI binding pipelines to
@MainActor. - Provide concrete Swift code signatures for critical architectural boundaries rather than abstract placeholders.
Output format
- Section 1: Architecture State Boundary Map (table format comparing Legacy Pattern to Swift 6 Target)
- Section 2: Actor Isolation & Sendability Contract (structural Swift pseudo-code or interface blueprints)
- Section 3: Phased Rollout Plan (3 execution phases with clear entry and exit criteria)
- Section 4: Diagnostics & Regression Protocol (bulleted list of validation commands and {{thread_safety_tooling}} steps)
- Total length: 450-800 words.
Self-review
- Confirm all 6 context variables are actively integrated in the reasoning steps.
- Verify that actor reentrancy edge cases are explicitly addressed in the isolation contract.
- Ensure strict adherence to the named sections and word limits.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.