Apple & iOS
AuraScore 83/100

Swift Concurrency Refactoring and Actor Isolation Specification

Generate an actionable architectural specification to refactor legacy iOS asynchronous code into strict Swift Concurrency and Actors.

Use when modernizing iOS asynchronous codebases to Swift 6 strict concurrency without runtime regressions. Ideal for debugging data races and thread-safety issues during architectural overhauls.

Template

Role: Staff iOS Systems Architect specializing in Swift Concurrency and memory safety.

Context

  • Target Module: {{target_module}}
  • Current Asynchronous Pattern: {{legacy_concurrency_pattern}}
  • Actor Isolation Boundaries: {{actor_isolation_rules}}
  • Memory Allocation Ceiling: {{memory_threshold_mb}}
  • Minimum iOS Deployment Target: {{ios_deployment_target}}

Task

Draft a comprehensive Swift Concurrency refactoring specification for {{target_module}} that replaces {{legacy_concurrency_pattern}} with structured concurrency, eliminates data races under Swift 6 language mode, and enforces strict actor isolation while maintaining performance within {{memory_threshold_mb}}.

Method

  1. Analyze {{target_module}} entry points currently bound to {{legacy_concurrency_pattern}} and classify thread hops.
  2. Map existing state variables to appropriate @MainActor, global actor, or custom actor boundaries following {{actor_isolation_rules}}.
  3. Identify non-Sendable type leaks across concurrency boundaries and specify @Sendable conversions or immutable value type replacements.
  4. Design structured task hierarchies using withTaskGroup or async let to replace unstructured callbacks and dispatch queues.
  5. Audit cancellation propagation paths to ensure immediate resource teardown and avoid detached task leaks.
  6. Specify backpressure and rate-limiting patterns for streaming updates using AsyncStream.
  7. Formulate a memory safety verification protocol to ensure heap usage does not exceed {{memory_threshold_mb}} during burst loads on {{ios_deployment_target}}.
  8. Define compiler diagnostic flag configurations and runtime Instruments verification strategies.

Constraints

  • MUST guarantee zero compiler warnings under Swift 6 strict concurrency checks.
  • MUST NOT introduce non-cooperative background thread blocking or Task.sleep workarounds.
  • All async API contracts MUST target {{ios_deployment_target}} without deprecated fallback shims.
  • Architectural diagrams and code examples must use idiomatic, production-ready Swift.

Output format

  • Section 1: Architectural Overview (Scope, Isolation Topology)
  • Section 2: Concurrency Model Transformations (Legacy vs Swift 6 Mappings)
  • Section 3: Sendable & Actor Boundary Specification (Type contracts)
  • Section 4: Memory & Performance Budget (Telemetry, Allocation Profile)
  • Section 5: Verification & Debugging Plan (Instruments recipes, unit test harnesses)

Self-review

  • Verify all legacy patterns from {{legacy_concurrency_pattern}} are fully addressed without dangling closures.
  • Confirm actor isolation logic matches {{actor_isolation_rules}} without creating deadlock hazards.
  • Ensure memory allocation limits adhere strictly to {{memory_threshold_mb}}.
AuraScore breakdown
83/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness5/5 · Strong

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-apple
software-engineering-debugging
swift
ios
concurrency