swift-concurrency
/swift-concurrency
Modern Swift Concurrency on iOS - async/await, structured concurrency, Task and Task.detached, actor and @MainActor isolation, Sendable and Swift 6 strict concurrency, AsyncSequence/AsyncStream, TaskGroup, async let, and bridging callbacks with withCheckedContinuation. Use when writing async iOS code, fixing data races or off-main-thread UI updates, parallelizing work, wrapping delegate/completion-handler APIs, or consuming Kotlin suspend/Flow exposed as Swift async. For reactive Publisher/subscriber pipelines use combine-framework; for SwiftUI state use swiftui-observation; for the KMP bridge
- Author
- TalissonVitorino ↗
- Repository
- kmp-ios-skills ↗
- Licence
- MIT
- Last repository change
- 25.08.2026
Assessment and security
- Files in this package
- 1
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 0
No signals detected. Repository changed on 25.08.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Modern Swift Concurrency on iOS - async/await, structured concurrency, Task and Task.detached, actor and @MainActor isolation, Sendable and Swift 6 strict concurrency, AsyncSequence/AsyncStream, TaskGroup, async let, and bridging callbacks with withCheckedContinuation. Use when writing async iOS code, fixing data races or off-main-thread UI updates, parallelizing work, wrapping delegate/completion-handler APIs, or consuming Kotlin suspend/Flow exposed as Swift async. For reactive Publisher/subscriber pipelines use combine-framework; for SwiftUI state use swiftui-observation; for the KMP bridge
Original author description
Modern Swift Concurrency on iOS - async/await, structured concurrency, Task and Task.detached, actor and @MainActor isolation, Sendable and Swift 6 strict concurrency, AsyncSequence/AsyncStream, TaskGroup, async let, and bridging callbacks with withCheckedContinuation. Use when writing async iOS code, fixing data races or off-main-thread UI updates, parallelizing work, wrapping delegate/completion-handler APIs, or consuming Kotlin suspend/Flow exposed as Swift async. For reactive Publisher/subscriber pipelines use combine-framework; for SwiftUI state use swiftui-observation; for the KMP bridge
How it works
- Overview
- When to use
- Quick reference
- Example — actor + @MainActor + continuation
- Common mistakes
- See also
SKILL.md preview
---
name: swift-concurrency
description: Modern Swift Concurrency on iOS - async/await, structured concurrency, Task and Task.detached, actor and @MainActor isolation, Sendable and Swift 6 strict concurrency, AsyncSequence/AsyncStream, TaskGroup, async let, and bridging callbacks with withCheckedContinuation. Use when writing async iOS code, fixing data races or off-main-thread UI updates, parallelizing work, wrapping delegate/completion-handler APIs, or consuming Kotlin suspend/Flow exposed as Swift async. For reactive Publisher/subscriber pipelines use combine-framework; for SwiftUI state use swiftui-observation; for the KMP bridge use kmp-ios-integration.
---
# Swift Concurrency
## Overview
Structured concurrency built on `async/await`. The compiler enforces isolation (`actor`, `@MainActor`) and, under Swift 6 strict concurrency, data-race safety via `Sendable`. Prefer this over GCD/`DispatchQueue` for new code.
## When to use
- Async iOS work: network, disk, or shared-KMP calls
- Updating UI safely from background work (`@MainActor`)
- Parallel work (`async let`, `TaskGroup`)
- Bridging callback/delegate APIs into `async` (`withCheckedContinuation`)
- Compiler errors like "call to main actor-isolated … in a synchronous nonisolated context" or `Sendable` warnings
- Consuming Kotlin `suspend`/`Flow` surfaced as Swift `async` (see kmp-ios-integration)
## Quick reference
| Need | Use |
|---|---|
| Run async work from sync code | `Task { await … }` |
| Main-thread isolation | `@MainActor` on type/func/closure |
| Parallel children, fixed count | `async let a = …; async let b = …; let (x, y) = await (a, b)` |
| Parallel children, dynamic | `withThrowingTaskGroup` |
| Serialize mutable state (no locks) | `actor` |
| Stream of values over time | `AsyncStream` / `AsyncSequence` |
| Wrap a completion-handler API | `withCheckedThrowingContinuation` |
| Opt a member out of actor isolation | `nonisolated` |
## Example — actor + @MainActor + continuation
```swift
actor ImageCache { // serialized state, no manual locks
private var store: [URL: Data] = [:]
func data(for url: URL) -> Data? { store[url] }
func insert(_ data: Data, for url: URL) { store[url] = data }
}
@MainActor // all UI state mutates on the main thread
@Observable final class FeedModel {
var items: [Item] = []
func load() async throws {
async let items = api.fetchItems() // these two run in parallel
async let promos = api.fetchPromos()
self.items = try await merge(items, promos) // already on the main actor
}
}
// Bridge a delegate/callback API into async/await
func currentLocation() async throws -> CLLocation {
try await withCheckedThrowingContinuation { continuation in
locationManager.requestLocation { result in
continuation.resume(with: result) // resume EXACTLY once, on every path
}
}
}
```
## Common mistakes
| Mistake | Fix |
|---|---|
| Heavy CPU work inside `Task {}` on the main actor | Use `Task.detached` or a background `actor` |
| Updating UI off the main thread | Annotate the model/view code `@MainActor` |
| Resuming a continuation twice or never | Resume exactly once on every path (incl. errors) |
| `Task {}` strongly capturing `self` in a view | Use the structured `.task {}` modifier or `[weak self]` |
| Assuming an `actor` is reentrancy-safe across `await` | State can change at suspension points — re-check invariants after `await` |
| Swift 6 `Sendable` errors | Make captured types `Sendable`, or isolate them to an actor |
## See also
- Reactive Publisher/subscriber pipelines: `combine-framework`
- SwiftUI state with `@Observable` (`@MainActor`): `swiftui-observation`
- Consuming KMP `suspend`/`Flow` as Swift async: `kmp-ios-integration`
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · TalissonVitorino/kmp-ios-skills | 100 | MIT |
| HoangNguyen0403/agent-skills-standard | 100 | MIT |
| rusel95/ios-agent-skills | 100 | MIT |
| velimirmueller/ai-development-skills | 100 | MIT |
| apexbymanish/claude-ai-agents-ios | 100 | MIT |
| JordanCoin/ios-skills-collection | 95 | MIT |
| JordanCoin/ios-skills-collection | 95 | MIT |
| tuist/fuckingapproachableswiftconcurrency | 95 | MIT |
Database snapshot: 13.11.2026 · package version 75e8c7280e8d (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Similar skills
- 100axiom-concurrency
Use when writing ANY async code, actors, or threads in an Apple-platform app, or seeing ANY concurrency error. Covers Swift 6 concurrency, @MainActor, Sendable, data races, async/await patterns. - 100axiom-concurrency
Use when writing ANY async code, actors, or threads in an Apple-platform app, or seeing ANY concurrency error. Covers Swift 6 concurrency, @MainActor, Sendable, data races, async/await patterns. - 95swift-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. Concrete actions include adding Sendable conformance, applying @MainActor… - 100swift
Use when writing Swift for iOS, macOS, or server-side. Covers value semantics, optionals, protocol-oriented design, structured concurrency with async/await and actors, and SwiftUI state management. Trigger on "migrate this completion handler to async/await", "sendable warnings… - 100swift-concurrency-pro
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. - 90ios-swift-concurrency
Use when implementing async/await, Task management, actors, or Combine reactive patterns in iOS applications.