swift-concurrency
Skill37 starsChanged 7 months agoMITView on GitHub
Expert guidance on Swift Concurrency best practices, patterns, and implementation. Use when developers mention: (1) Swift Concurrency, async/await, actors, or tasks, (2) "use Swift Concurrency" or "modern concurrency patterns", (3) migrating to Swift 6, (4) data races or thread safety issues, (5) refactoring closures to async/await, (6) @MainActor, Sendable, or actor isolation, (7) concurrent code architecture or performance optimization, (8) concurrency-related linter warnings (SwiftLint or similar; e.g. async_without_await, Sendable/actor isolation/MainActor lint).
13 other projects use a version of this, 7 of them edited.
Adopted by
Most recently taken up by
- Fe2-O3/swift-field-guideedited, first seen Sep 9, 2026
- AvdLee/Swift-Concurrency-Agent-Skilledited, first seen Aug 7, 2026
- K95M65/AI_ONBOARDedited, first seen Jul 18, 2026
- dpearson2699/swift-ios-skillstheir own version, first seen Jul 13, 2026
- rusel95/ios-agent-skillstheir own version, first seen Apr 16, 2026
- Prisma-Labs-Dev/apple-skillstheir own version, first seen Apr 14, 2026
Used with
Projects with it also use swift-architecture.
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.
pluginagentmarketplaceSkillswift-architecture
Master iOS/macOS app architecture - MVVM, Clean Architecture, Coordinator, DI, Repository
Also in 3 projects that use this
Other versions13 projects use a version of this.
Word for word · 0
None found.
Edited · 7
- AvdLee/Swift-Concurrency-Agent-Skill★ 1.7k16% same
- wendylabsinc/claude-skills★ 6263% same
- nonameplum/agent-skills★ 1796% same
- henryhudson/swift-claude-skills★ 125% same
- KKodiac/agent-skills★ 196% same
- Fe2-O3/swift-field-guide★ 010% same
- K95M65/AI_ONBOARD★ 013% same
Wrote their own version · 6
- dpearson2699/swift-ios-skills★ 1.2ksame name
- Prisma-Labs-Dev/apple-skills★ 337same name
- jamesrochabrun/skills★ 214same name
- rusel95/ios-agent-skills★ 11same name
- pluginagentmarketplace/custom-plugin-swift★ 9same name
- piemonte/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository5 other files it gives its agents.
- swift-code-reviewerSkill
- swift-expertSkill
- swift-testingSkill
- swiftui-expert-skillSkill
- swiftui-ui-patternsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
27 rules. 0 are common, 8 are distinctive, and 19 are very specific to this project.
0
Common
Most of the 12 edited versions we read keep these.
8
Distinctive
This author's own choices. Worth a look.
19
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Before proposing fixes, identify the isolation boundary: @MainActor, custom actor, actor instance isolation, or nonisolated.
- Very specific: line 15
Do not recommend @MainActor as a blanket fix.
- Very specific: line 16
Prefer structured concurrency (child tasks, task groups) over unstructured tasks.
- Very specific: line 17
If recommending @preconcurrency, @unchecked Sendable, or nonisolated(unsafe), require:
- Very specific: line 27
Default actor isolation (is the module default @MainActor or nonisolated?)
- Very specific: line 35
Check Package.swift for .defaultIsolation(MainActor.self).
- Very specific: line 37
Check for strict concurrency flags: .enableExperimentalFeature("StrictConcurrency=targeted") (or similar).
- Very specific: line 38
Check tools version at the top: // swift-tools-version: ...
- Distinctive: line 45
If any of these are unknown, ask the developer to confirm them before giving migration-sensitive guidance.
- Distinctive: line 49
When a developer needs concurrency guidance, follow this decision tree:
- Very specific: line 52
Read references/async-await-basics.md for foundational patterns
- Very specific: line 72
Read references/threading.md for thread/task relationship and isolation
- Very specific: line 75
Read references/memory-management.md for retain cycle prevention
- Very specific: line 80
Use references/linting.md for rule intent and preferred fixes.
- Very specific: line 82
Remove async if not required.
- Very specific: line 90
Use references/threading.md to avoid thread-centric debugging and rely on isolation + Instruments
- Very specific: line 92
Use references/testing.md (await fulfillment(of:) and Swift Testing patterns)
- Very specific: line 94
Use references/core-data.md (DAO/NSManagedObjectID, default isolation conflicts)
- Distinctive: line 213
Prefer structured concurrency: - Use task groups over unstructured tasks when possible
- Distinctive: line 214
Minimize suspension points: - Keep actor-isolated sections small to reduce context switches
- Distinctive: line 215
Use @MainActor judiciously: - Only for truly UI-related code
- Distinctive: line 217
Handle cancellation: - Check Task.isCancelled in long-running operations
- Distinctive: line 218
Avoid blocking: - Never use semaphores or locks in async contexts
- Distinctive: line 219
Test concurrent code: - Use proper async test methods and consider timing issues
- Very specific: line 225
Run tests, especially concurrency-sensitive ones (see references/testing.md).
- Very specific: line 226
If performance-related, verify with Instruments (see references/performance.md).
- Very specific: line 227
If lifetime-related, verify deinit/cancellation behavior (see references/memory-management.md).
“Common” is measured: kept by at least 6 in 10 of the 12 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.
Files
Swift Concurrency
Overview
This skill provides expert guidance on Swift Concurrency, covering modern async/await patterns, actors, tasks, Sendable conformance, and migration to Swift 6. Use this skill to help developers write safe, performant concurrent code and navigate the complexities of Swift's structured concurrency model.
Agent Behavior Contract (Follow These Rules)
- Analyze the project/package file to find out which Swift language mode (Swift 5.x vs Swift 6) and which Xcode/Swift toolchain is used when advice depends on it.
- Before proposing fixes, identify the isolation boundary:
@MainActor, custom actor, actor instance isolation, or nonisolated. - Do not recommend
@MainActoras a blanket fix. Justify why main-actor isolation is correct for the code. - Prefer structured concurrency (child tasks, task groups) over unstructured tasks. Use
Task.detachedonly with a clear reason. - If recommending
@preconcurrency,@unchecked Sendable, ornonisolated(unsafe), require:- a documented safety invariant
- a follow-up ticket to remove or migrate it
- For migration work, optimize for minimal blast radius (small, reviewable changes) and add verification steps.
- Course references are for deeper learning only. Use them sparingly and only when they clearly help answer the developer’s question.
Project Settings Intake (Evaluate Before Advising)
Concurrency behavior depends on build settings. Always try to determine:
- Default actor isolation (is the module default
@MainActorornonisolated?) - Strict concurrency checking level (minimal/targeted/complete)
- Whether upcoming features are enabled (especially
NonisolatedNonsendingByDefault) - Swift language mode (Swift 5.x vs Swift 6) and SwiftPM tools version
Manual checks (no scripts)
- SwiftPM:
- Check
Package.swiftfor.defaultIsolation(MainActor.self). - Check
Package.swiftfor.enableUpcomingFeature("NonisolatedNonsendingByDefault"). - Check for strict concurrency flags:
.enableExperimentalFeature("StrictConcurrency=targeted")(or similar). - Check tools version at the top:
// swift-tools-version: ...
- Check
- Xcode projects:
- Search
project.pbxprojfor:SWIFT_DEFAULT_ACTOR_ISOLATIONSWIFT_STRICT_CONCURRENCYSWIFT_UPCOMING_FEATURE_(and/orSWIFT_ENABLE_EXPERIMENTAL_FEATURES)
- Search
If any of these are unknown, ask the developer to confirm them before giving migration-sensitive guidance.
Quick Decision Tree
When a developer needs concurrency guidance, follow this decision tree:
- Starting fresh with async code?
- Read
references/async-await-basics.mdfor foundational patterns - For parallel operations →
references/tasks.md(async let, task groups)
- Read
- Protecting shared mutable state?
- Need to protect class-based state →
references/actors.md(actors, @MainActor) - Need thread-safe value passing →
references/sendable.md(Sendable conformance)
- Need to protect class-based state →
- Managing async operations?
- Structured async work →
references/tasks.md(Task, child tasks, cancellation) - Streaming data →
references/async-sequences.md(AsyncSequence, AsyncStream)
- Structured async work →
- Working with legacy frameworks?
- Core Data integration →
references/core-data.md - General migration →
references/migration.md
- Core Data integration →
- Performance or debugging issues?
- Slow async code →
references/performance.md(profiling, suspension points) - Testing concerns →
references/testing.md(XCTest, Swift Testing)
- Slow async code →
- Understanding threading behavior?
- Read
references/threading.mdfor thread/task relationship and isolation
- Read
- Memory issues with tasks?
- Read
references/memory-management.mdfor retain cycle prevention
- Read
Triage-First Playbook (Common Errors -> Next Best Move)
- SwiftLint concurrency-related warnings
- Use
references/linting.mdfor rule intent and preferred fixes; avoid dummy awaits as “fixes”.
- Use
- SwiftLint
async_without_awaitwarning- Remove
asyncif not required; if required by protocol/override/@concurrent, prefer narrow suppression over adding fake awaits. Seereferences/linting.md.
- Remove
- "Sending value of non-Sendable type ... risks causing data races"
- First: identify where the value crosses an isolation boundary
- Then: use
references/sendable.mdandreferences/threading.md(especially Swift 6.2 behavior changes)
- "Main actor-isolated ... cannot be used from a nonisolated context"
- First: decide if it truly belongs on
@MainActor - Then: use
references/actors.md(global actors,nonisolated, isolated parameters) andreferences/threading.md(default isolation)
- First: decide if it truly belongs on
- "Class property 'current' is unavailable from asynchronous contexts" (Thread APIs)
- Use
references/threading.mdto avoid thread-centric debugging and rely on isolation + Instruments
- Use
- XCTest async errors like "wait(...) is unavailable from asynchronous contexts"
- Use
references/testing.md(await fulfillment(of:)and Swift Testing patterns)
- Use
- Core Data concurrency warnings/errors
- Use
references/core-data.md(DAO/NSManagedObjectID, default isolation conflicts)
- Use
Core Patterns Reference
When to Use Each Concurrency Tool
async/await - Making existing synchronous code asynchronous
// Use for: Single asynchronous operations
func fetchUser() async throws -> User {
try await networkClient.get("/user")
}async let - Running multiple independent async operations in parallel
// Use for: Fixed number of parallel operations known at compile time
async let user = fetchUser()
async let posts = fetchPosts()
let profile = try await (user, posts)Task - Starting unstructured asynchronous work
// Use for: Fire-and-forget operations, bridging sync to async contexts
Task {
await updateUI()
}Task Group - Dynamic parallel operations with structured concurrency
// Use for: Unknown number of parallel operations at compile time
await withTaskGroup(of: Result.self) { group in
for item in items {
group.addTask { await process(item) }
}
}Actor - Protecting mutable state from data races
// Use for: Shared mutable state accessed from multiple contexts
actor DataCache {
private var cache: [String: Data] = [:]
func get(_ key: String) -> Data? { cache[key] }
}@MainActor - Ensuring UI updates on main thread
// Use for: View models, UI-related classes
@MainActor
class ViewModel: ObservableObject {
@Published var data: String = ""
}Common Scenarios
Scenario: Network request with UI update
Task { @concurrent in
let data = try await fetchData() // Background
await MainActor.run {
self.updateUI(with: data) // Main thread
}
}Scenario: Multiple parallel network requests
async let users = fetchUsers()
async let posts = fetchPosts()
async let comments = fetchComments()
let (u, p, c) = try await (users, posts, comments)Scenario: Processing array items in parallel
await withTaskGroup(of: ProcessedItem.self) { group in
for item in items {
group.addTask { await process(item) }
}
for await result in group {
results.append(result)
}
}Swift 6 Migration Quick Guide
Key changes in Swift 6:
- Strict concurrency checking enabled by default
- Complete data-race safety at compile time
- Sendable requirements enforced on boundaries
- Isolation checking for all async boundaries
For detailed migration steps, see references/migration.md.
Reference Files
Load these files as needed for specific topics:
async-await-basics.md- async/await syntax, execution order, async let, URLSession patternstasks.md- Task lifecycle, cancellation, priorities, task groups, structured vs unstructuredthreading.md- Thread/task relationship, suspension points, isolation domains, nonisolatedmemory-management.md- Retain cycles in tasks, memory safety patternsactors.md- Actor isolation, @MainActor, global actors, reentrancy, custom executors, Mutexsendable.md- Sendable conformance, value/reference types, @unchecked, region isolationlinting.md- Concurrency-focused lint rules and SwiftLintasync_without_awaitasync-sequences.md- AsyncSequence, AsyncStream, when to use vs regular async methodscore-data.md- NSManagedObject sendability, custom executors, isolation conflictsperformance.md- Profiling with Instruments, reducing suspension points, execution strategiestesting.md- XCTest async patterns, Swift Testing, concurrency testing utilitiesmigration.md- Swift 6 migration strategy, closure-to-async conversion, @preconcurrency, FRP migration
Best Practices Summary
- Prefer structured concurrency - Use task groups over unstructured tasks when possible
- Minimize suspension points - Keep actor-isolated sections small to reduce context switches
- Use @MainActor judiciously - Only for truly UI-related code
- Make types Sendable - Enable safe concurrent access by conforming to Sendable
- Handle cancellation - Check Task.isCancelled in long-running operations
- Avoid blocking - Never use semaphores or locks in async contexts
- Test concurrent code - Use proper async test methods and consider timing issues
Verification Checklist (When You Change Concurrency Code)
- Confirm build settings (default isolation, strict concurrency, upcoming features) before interpreting diagnostics.
- After refactors:
- Run tests, especially concurrency-sensitive ones (see
references/testing.md). - If performance-related, verify with Instruments (see
references/performance.md). - If lifetime-related, verify deinit/cancellation behavior (see
references/memory-management.md).
- Run tests, especially concurrency-sensitive ones (see
Glossary
See references/glossary.md for quick definitions of core concurrency terms used across this skill.
Note: This skill is based on the comprehensive Swift Concurrency Course by Antoine van der Lee.
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
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.

