Skill

Fix Swift Concurrency Issues

A skill that reviews and fixes Swift 6.2+ concurrency diagnostics using actor isolation and Sendable safety with minimal behavior change.


81
Spark score
out of 100
Updated 27 days ago
Version 13.9.0

Add to Favorites

Why it matters

Enhance Swift code quality by identifying and resolving concurrency-related compiler diagnostics. Ensure data-race safety and adherence to modern concurrency patterns in Swift 6.2+ codebases.

Outcomes

What it gets done

01

Analyze Swift compiler diagnostics for concurrency issues.

02

Apply actor isolation and Sendable safety fixes.

03

Verify fixes by rebuilding and running test suites.

04

Migrate code to utilize modern concurrency patterns.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/ag-swift-concurrency-expert | bash

Overview

Swift Concurrency Expert

A skill that reviews and fixes Swift 6.2+ concurrency compiler diagnostics using actor isolation and Sendable safety, applying the smallest safe change to preserve existing behavior. Use it for Swift 6.2+ concurrency diagnostics and actor-isolation questions specifically, not for general Swift code review unrelated to concurrency.

What it does

This skill reviews and fixes Swift Concurrency issues in Swift 6.2+ codebases by applying actor isolation, Sendable safety, and modern concurrency patterns while minimizing behavior changes. Its triage step captures the exact compiler diagnostics and offending symbols, checks project concurrency settings (Swift language version 6.2+, strict concurrency level, whether approachable concurrency/main-actor-by-default is enabled), identifies the current actor context (@MainActor, actor, nonisolated), and confirms whether the code is UI-bound or meant to run off the main actor. It then applies the smallest safe fix that preserves existing behavior: annotating UI-bound types with @MainActor so all stored state and methods are automatically isolated, scoping protocol conformances to @MainActor when a conforming type's members are main-actor-isolated but the protocol method isn't, protecting global/static mutable state with @MainActor or moving it into an actor, moving expensive work into a @concurrent async function on a nonisolated type (or using Task.detached) to keep it off the main actor, and for Sendable errors preferring immutable/value types, adding Sendable conformance only when actually correct, and avoiding @unchecked Sendable unless thread safety can be proven. It verifies each fix by rebuilding to confirm all concurrency diagnostics resolve with no new warnings, then running the test suite to catch regressions - since concurrency changes can introduce subtle runtime issues even on a clean build - iterating back to triage if new warnings surface. It demonstrates three complete before/after examples: annotating a SwiftUI ViewModel class with @MainActor to eliminate a data-race warning, scoping a protocol conformance extension to @MainActor to satisfy an isolation mismatch, and moving heavy computation off the main actor via either Task.detached(priority: .userInitiated) or a Swift 6.2+ @concurrent async function. Reference files provide deeper detail on Swift 6.2 concurrency changes, approachable concurrency mode, and SwiftUI-specific concurrency guidance from WWDC.

When to use - and when NOT to

Use it when reviewing Swift concurrency usage, fixing compiler diagnostics related to concurrency, or needing guidance on actor isolation, Sendable, @MainActor, or async migration. It is scoped to Swift 6.2+ concurrency specifically, not general Swift code review or non-concurrency-related compiler errors.

Inputs and outputs

Inputs: the exact Swift compiler concurrency diagnostics, the offending code, and the project's concurrency settings (language version, strict concurrency level, approachable concurrency status).
Outputs: the smallest safe code fix (actor annotation, isolated protocol conformance, moved background work, or corrected Sendable conformance) that resolves the diagnostic without introducing new warnings or test regressions.

@MainActor
class ViewModel: ObservableObject {
    @Published var title: String = ""
    func load() { title = "Loaded" }
}

Who it's for

iOS/macOS developers fixing Swift 6.2+ concurrency compiler errors or migrating code to strict concurrency, who need minimal, correct actor-isolation fixes rather than broad rewrites.

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.