agentsclimarketplace

Swift concurrency pro

Skill laxrajpurohit/swift-skills-pro/swift-concurrency-pro/skills/swift-concurrency-pro

Modern, original agent skills for Swift and Apple-platform development

Install
npx -y skills add laxrajpurohit/swift-skills-pro --skill swift-concurrency-pro

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 5 stars5 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when writing async/await code, fixing Sendable or data-race errors, enabling strict concurrency, using actors, or migrating from completion handlers in Swift 6.

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

3.5 KB, as published. Nobody here has run it

Swift Concurrency Pro

Write correct, data-race-free concurrent Swift. Target Swift 6 strict concurrency.

When to use

  • Writing or reviewing async/await code.
  • Fixing Sendable / data-race / actor-isolation errors.
  • Migrating completion-handler APIs to async.

Trigger: /swift-concurrency-pro.

Core principles

  • Swift 6 enforces data isolation at compile time. Treat every concurrency warning as a real bug, not noise.
  • UI and view models are @MainActor. Background work runs off the main actor.
  • Share mutable state through an actor, never a lock + global.
  • Make types crossing concurrency boundaries Sendable.

async/await over completion handlers

func loadUser(completion: @escaping (Result<User, Error>) -> Void) { ... }

func loadUser() async throws -> User { ... }

Wrap legacy callbacks with continuations:

func loadUser() async throws -> User {
    try await withCheckedThrowingContinuation { cont in
        legacyLoad { result in cont.resume(with: result) }
    }
}

Resume a continuation exactly once — never zero, never twice.

Actors for shared mutable state

❌ Lock around shared dictionary

final class Cache {
    private var store: [String: Data] = [:]
    private let lock = NSLock()
    func set(_ d: Data, _ k: String) { lock.lock(); store[k] = d; lock.unlock() }
}

actor Cache {
    private var store: [String: Data] = [:]
    func set(_ d: Data, for k: String) { store[k] = d }
    func get(_ k: String) -> Data? { store[k] }
}

Access is await cache.set(...). Don't expose var actor state directly across actors.

@MainActor for UI

@MainActor
@Observable
final class FeedModel {
    var posts: [Post] = []
    func refresh() async {
        let fetched = await api.posts()   // api hops off main as needed
        posts = fetched                   // back on main, safe
    }
}

Don't sprinkle DispatchQueue.main.async — annotate with @MainActor instead.

Sendable

  • struct/enum of Sendable members → automatically Sendable.
  • Final classes with immutable state → mark Sendable.
  • Mutable classes shared across actors → make it an actor, or isolate it.

class Settings { var theme = "light" }   // shared across tasks → data race

actor Settings { var theme = "light" }
// or, if truly immutable:
struct Settings: Sendable { let theme: String }

Structured concurrency

Use async let / TaskGroup for parallel work; they auto-cancel and propagate errors.

async let a = api.profile()
async let b = api.feed()
let (profile, feed) = try await (a, b)

Avoid unstructured Task { } for work tied to a view's lifetime — use .task so it cancels on disappear.

Common mistakes checklist

  • Resuming a continuation zero or multiple times.
  • DispatchQueue.main.async instead of @MainActor.
  • Lock-guarded shared state that should be an actor.
  • Non-Sendable type sent across a concurrency boundary.
  • Detached Task {} for view-scoped work (won't cancel).
  • Suppressing concurrency warnings instead of fixing isolation.

Output format (when reviewing)

Per issue: file:line, the isolation/Sendable rule violated, before/after fix. End with the highest-risk data races first.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.