agentleFS
igorkulmanigorkulman/pi-skills/skills/swift-concurrency/SKILL.md

swift-concurrency

Skill3 starsChanged 2 months agoMITView on GitHub

Implement, diagnose, review, or migrate Swift code involving async/await, actors, tasks, cancellation, Sendable, isolation diagnostics, continuations, AsyncSequence, or async tests. Use for Swift concurrency compiler errors and runtime race or task-lifetime problems. Do not use for ordinary synchronous Swift work, unrelated build failures, or project-specific migration policy when a more specific project skill applies.

25 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use swiftdata, swiftui-expert-skill and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • Prisma-Labs-DevSkill

    swiftdata

    API reference: SwiftData. Query for @Model, ModelContext, @Query, schema migrations.

    Also in 3 projects that use this

  • xfstudioSkill

    swiftui-expert-skill

    Write, review, or improve SwiftUI code following best practices for state management, view composition, performance, modern APIs, Swift concurrency, and iOS 26+ Liquid Glass adoption. Use when building new SwiftUI features, refactoring existing views, reviewing code quality, or adopting modern SwiftUI patterns.

    Also in 8 projects that use this

  • pluginagentmarketplaceSkill

    swift-testing

    Test Swift applications - XCTest, Swift Testing, UI tests, mocking, TDD, CI/CD

    Also in 4 projects that use this

  • eugenepyvovarovSkill

    swift-concurrency-expert

    Swift Concurrency review and remediation for Swift 6.2+. Use when asked to review Swift Concurrency usage, improve concurrency compliance, or fix Swift concurrency compiler errors in a feature or file.

    Also in 4 projects that use this

  • AvdLeeSkill

    swift-testing-expert

    Expert guidance for Swift Testing: test structure, #expect/#require macros, traits and tags, parameterized tests, test plans, parallel execution, async waiting patterns, and XCTest migration. Use when writing new Swift tests, modernizing XCTest suites, debugging flaky tests, or improving test quality and maintainability in Apple-platform or Swift server projects.

    Also in 3 projects that use this

  • dadederkSkill

    ios-accessibility

    Expert guidance on iOS accessibility best practices, patterns, and implementation. Use when developers mention: (1) iOS accessibility, VoiceOver, Dynamic Type, or assistive technologies, (2) accessibility labels, traits, hints, or values, (3) automated accessibility testing, auditing, or manual testing, (4) Switch Control, Voice Control, or Full Keyboard Access, (5) inclusive design or accessibility culture, (6) making apps work for users with disabilities.

    Also in 3 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

22 rules. 0 are common, 13 are distinctive, and 9 are very specific to this project.

  • 0

    Common

    Most of the 24 edited versions we read keep these.

  • 13

    Distinctive

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before giving version-sensitive advice or changing code, inspect the smallest relevant set of settings:

    line 13
  2. Distinctive:

    Do not assume that the package tools version, Swift language mode, compiler version, and default actor isolation are the same thing.

    line 20
  3. Distinctive:

    Prefer fixes in this order:

    line 31
  4. Very specific:

    Keep work in its rightful isolation domain and pass immutable Sendable values.

    line 33
  5. Distinctive:

    Add precise annotations to declarations or protocol requirements where they express the API contract.

    line 35
  6. Very specific:

    Use sending only when ownership transfer matches the actual lifetime of the value.

    line 36
  7. Distinctive:

    Use compatibility escapes only as a last resort.

    line 37
  8. Very specific:

    Never apply @MainActor to an entire type or module solely because it removes errors.

    line 39
  9. Very specific:

    Prefer structured child tasks: direct await, async let, and task groups.

    line 43
  10. Very specific:

    Use unstructured Task only when bridging from synchronous code or when an explicit owner manages its lifetime, cancellation, errors, and …

    line 44
  11. Very specific:

    Use Task.detached only when deliberately discarding actor context, task-local values, and inherited priority is correct.

    line 46
  12. Very specific:

    Never block a cooperative executor with semaphores or synchronous waits.

    line 48
  13. Very specific:

    Treat await as a possible suspension and interleaving point, not evidence of a thread switch.

    line 49
  14. Very specific:

    Before using @preconcurrency, @unchecked Sendable, nonisolated(unsafe), or MainActor.assumeIsolated:

    line 54
  15. Distinctive:

    document the concrete invariant that makes the operation safe

    line 56
  16. Distinctive:

    Do not add a package dependency, change strict-concurrency settings, or change default actor isolation merely to avoid fixing diagnostics …

    line 61
  17. Distinctive:

    Read only the references needed for the task, resolving paths relative to this skill:

    line 65
  18. Distinctive:

    After changing concurrency code:

    line 78
  19. Distinctive:

    Run focused tests that exercise ordering, cancellation, error propagation, or lifetime—not merely the happy-path result.

    line 81
  20. Distinctive:

    Use Thread Sanitizer or Instruments when runtime races, hangs, excessive task creation, or performance are part of the problem.

    line 82
  21. Distinctive:

    Verify supported Swift language modes separately when a package intentionally supports more than one.

    line 83
  22. Distinctive:

    Follow the project's Xcode verification route.

    line 86

“Common” is measured: kept by at least 6 in 10 of the 24 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Swift Concurrency

Reason from the project's actual isolation model and compiler configuration. Do not apply concurrency annotations merely to silence diagnostics.

Intake

Before giving version-sensitive advice or changing code, inspect the smallest relevant set of settings:

  • SwiftPM: tools version, swiftLanguageModes, target swiftSettings, .defaultIsolation(...), strict-concurrency settings, and upcoming features in Package.swift.
  • Xcode: SWIFT_VERSION, SWIFT_STRICT_CONCURRENCY, SWIFT_DEFAULT_ACTOR_ISOLATION, and SWIFT_UPCOMING_FEATURE_* in project settings.
  • The exact compiler diagnostic and the declaration plus call sites on both sides of the reported isolation boundary.
  • Deployment targets when a proposed API has OS availability constraints.

Do not assume that the package tools version, Swift language mode, compiler version, and default actor isolation are the same thing. If a required setting cannot be determined, state the assumption and ask only when it materially changes the solution.

Diagnostic method

  1. Identify every relevant isolation domain: @MainActor, another global actor, an actor instance, task isolation, or nonisolated code.
  2. Identify mutable state and who owns it.
  3. Mark values that cross an isolation boundary and determine whether they are Sendable, proven disconnected for sending, or should not cross at all.
  4. Account for suspension and actor reentrancy; values read before await may be stale afterward.
  5. Decide whether the operation needs serialization, parallelism, or simply asynchronous waiting.
  6. Fix the model at the narrowest stable boundary, then compile before addressing secondary diagnostics.

Prefer fixes in this order:

  1. Keep work in its rightful isolation domain and pass immutable Sendable values.
  2. Give shared mutable state one clear owner, often an actor or an existing global actor.
  3. Add precise annotations to declarations or protocol requirements where they express the API contract.
  4. Use sending only when ownership transfer matches the actual lifetime of the value.
  5. Use compatibility escapes only as a last resort.

Never apply @MainActor to an entire type or module solely because it removes errors. UI state commonly belongs on MainActor; networking, storage, parsing, and CPU-heavy work do not automatically belong there.

Execution rules

  • Prefer structured child tasks: direct await, async let, and task groups.
  • Use unstructured Task only when bridging from synchronous code or when an explicit owner manages its lifetime, cancellation, errors, and result.
  • Task inherits surrounding isolation; it is not a generic “background thread” primitive.
  • Use Task.detached only when deliberately discarding actor context, task-local values, and inherited priority is correct.
  • Cancellation is cooperative. Propagate CancellationError, check cancellation in long loops, and cancel owned long-lived tasks.
  • Never block a cooperative executor with semaphores or synchronous waits. Never hold a lock across an await.
  • Treat await as a possible suspension and interleaving point, not evidence of a thread switch.
  • Measure before changing isolation for performance. @concurrent selects generic-executor semantics on supporting toolchains; it does not promise a particular thread.

Unsafe and compatibility features

Before using @preconcurrency, @unchecked Sendable, nonisolated(unsafe), or MainActor.assumeIsolated:

  • document the concrete invariant that makes the operation safe
  • scope the escape as narrowly as possible
  • explain why a checked design is not currently practical
  • identify removal work; create an external ticket only when explicitly authorized

Do not add a package dependency, change strict-concurrency settings, or change default actor isolation merely to avoid fixing diagnostics unless the user explicitly requested that migration or dependency change.

Reference routing

Read only the references needed for the task, resolving paths relative to this skill:

  • references/isolation-and-sendability.md: actors, global actors, reentrancy, Sendable, sending, and unsafe escapes.
  • references/tasks-and-cancellation.md: structured and unstructured tasks, cancellation, errors, priorities, and task lifetime.
  • references/diagnostics-and-migration.md: common diagnostics, build settings, Swift language-mode migration, @concurrent, and default isolation.
  • references/async-streams-and-continuations.md: callback bridging, continuations, AsyncSequence, and stream lifetime.
  • references/testing.md: deterministic tests for async and actor-isolated behavior using XCTest or Swift Testing.
  • references/core-data.md: Core Data confinement, NSManagedObjectID, snapshots, and advanced executor integration.

For compiler- or SDK-sensitive syntax, prefer the available Xcode MCP Apple-documentation and Swift-snippet tools over memory. Do not load every reference preemptively.

Verification

After changing concurrency code:

  1. Re-run the focused compiler diagnostic or build with the same settings that produced it.
  2. Run focused tests that exercise ordering, cancellation, error propagation, or lifetime—not merely the happy-path result.
  3. Use Thread Sanitizer or Instruments when runtime races, hangs, excessive task creation, or performance are part of the problem.
  4. Verify supported Swift language modes separately when a package intentionally supports more than one.
  5. Report unsafe escapes, assumptions, untested scheduling behavior, and unavailable verification tools.

Follow the project's Xcode verification route. A successful build proves only that the checked configuration compiled; it does not prove cancellation, ordering, lifetime, or race freedom at runtime.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.