Swift Concurrency and Actor Isolation Migration Specification
Design a technical specification to migrate legacy Grand Central Dispatch codebases to modern Swift structured concurrency.
Use this template when refactoring legacy multi-threaded iOS modules into Swift async/await and Actor-isolated pipelines. It guarantees safety against data races while satisfying strict deployment targets.
Role: Staff iOS Systems Architect specializing in Swift runtime internals and thread sanitization.
Context
- Target Application: {{app_name}}
- Refactored Module: {{target_module}}
- Current Concurrency Pattern: {{concurrency_model_current}}
- Critical Thread-Safety Hazards: {{thread_safety_risks}}
- Minimum Target OS: {{minimum_ios_version}}
- Performance and Latency Budgets: {{performance_targets}}
Task
Produce an exhaustive engineering technical specification for transitioning {{target_module}} in {{app_name}} from {{concurrency_model_current}} to Swift 6 structured concurrency and actors, resolving {{thread_safety_risks}} without exceeding {{performance_targets}}.
Method
- Map all mutable shared state across {{target_module}} and evaluate actor boundary isolation requirements.
- Identify callback-based APIs and define async/await signature replacements with appropriate task cancellation propagation.
- Design GlobalActor or dedicated actor boundaries to mitigate {{thread_safety_risks}} while avoiding MainActor contention.
- Define TaskGroup execution strategies for parallel asynchronous operations aligned with {{performance_targets}}.
- Audit bridging mechanisms between legacy completion handlers and async/await using CheckedContinuation safeguards.
- Formulate compiler flag strategies for Swift 6 complete concurrency checking compatibility on {{minimum_ios_version}}.
- Detail thread sanitization validation routines, XCTest asynchronous assertions, and performance profiling runs.
Constraints
- MUST maintain strict backward deployment compatibility with {{minimum_ios_version}}.
- MUST NOT leave unchecked continuations that risk thread starvation or memory leaks.
- All async API contracts must implement explicit cooperative cancellation checks.
- Specification must provide concrete Swift code signatures for critical domain models.
Output format
Provide the specification in four structured markdown sections:
- Architecture Overview (Actor isolation boundaries and state lifecycle diagram/table)
- Concurrency Interface Signatures (Typed Swift signatures and error-handling paradigms)
- Task Lifecycle and Cancellation Strategy (Propagation flow and continuation safety rules)
- Verification and Benchmark Plan (Instruments profiling steps and Thread Sanitizer test suite) Total document length must remain between 400 and 700 words.
Self-review
- Verify all variables ({{app_name}}, {{target_module}}, {{concurrency_model_current}}, {{thread_safety_risks}}, {{minimum_ios_version}}, {{performance_targets}}) are addressed.
- Confirm no usage of deprecated DispatchGroup or lock primitives in proposed Swift signatures.
- Ensure exact compliance with the four specified section headers.
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.