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. 1. 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. 2. Before proposing fixes, iden
@MainActor, custom actor, actor instance isolation, or nonisolated.@MainActor as a blanket fix. Justify why main-actor isolation is correct for the code.Task.detached only with a clear reason.@preconcurrency, @unchecked Sendable, or nonisolated(unsafe), require:
Read on Package.swift for SwiftPM settings (tools version, strict concurrency flags, upcoming features)Grep for SWIFT_STRICT_CONCURRENCY or SWIFT_DEFAULT_ACTOR_ISOLATION in .pbxproj filesGrep for SWIFT_UPCOMING_FEATURE_ to find enabled upcoming features@MainActor or nonisolated?)NonisolatedNonsendingByDefault)Package.swift for .defaultIsolation(MainActor.self).Package.swift for .enableUpcomingFeature("NonisolatedNonsendingByDefault")..enableExperimentalFeature("StrictConcurrency=targeted") (or similar).// swift-tools-version: ...project.pbxproj for:
SWIFT_DEFAULT_ACTOR_ISOLATIONSWIFT_STRICT_CONCURRENCYSWIFT_UPCOMING_FEATURE_ (and/or SWIFT_ENABLE_EXPERIMENTAL_FEATURES)references/async-await-basics.md for foundational patternsreferences/tasks.md (async let, task groups)references/actors.md (actors, @MainActor)references/sendable.md (Sendable conformance)references/tasks.md (Task, child tasks, cancellation)references/async-sequences.md (AsyncSequence, AsyncStream)references/core-data.mdreferences/migration.mdreferences/performance.md (profiling, suspension points)references/testing.md (XCTest, Swift Testing)references/threading.md for thread/task relationship and isolationreferences/memory-management.md for retain cycle preventionreferences/linting.md for rule intent and preferred fixes; avoid dummy awaits as “fixes”.async_without_await warning
async if not required; if required by protocol/override/@concurrent, prefer narrow suppression over adding fake awaits. See references/linting.md.references/sendable.md and references/threading.md (especially Swift 6.2 behavior changes)@MainActorreferences/actors.md (global actors, nonisolated, isolated parameters) and references/threading.md (default isolation)references/threading.md to avoid thread-centric debugging and rely on isolation + Instrumentsreferences/testing.md (await fulfillment(of:) and Swift Testing patterns)references/core-data.md (DAO/NSManagedObjectID, default isolation conflicts)// 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 = "" }
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) } }
references/migration.md.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 SwiftLint async_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 migrationreferences/testing.md).references/performance.md).references/memory-management.md).references/glossary.md for quick definitions of core concurrency terms used across this skill.