Skip to content
Skills Library
Programming · Building & coding

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

Licence
MIT
Last repository change
25.08.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 25.08.2026, without references to retired models or APIs.

Licence

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

  1. Overview
  2. When to use
  3. Quick reference
  4. Example — actor + @MainActor + continuation
  5. Common mistakes
  6. See also
Original SKILL.md headings · 76 lines, 474 words
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

RepositoryScoreLicence
This page · TalissonVitorino/kmp-ios-skills100MIT
HoangNguyen0403/agent-skills-standard100MIT
rusel95/ios-agent-skills100MIT
velimirmueller/ai-development-skills100MIT
apexbymanish/claude-ai-agents-ios100MIT
JordanCoin/ios-skills-collection95MIT
JordanCoin/ios-skills-collection95MIT
tuist/fuckingapproachableswiftconcurrency95MIT

Database snapshot: 13.11.2026 · package version 75e8c7280e8d (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

: harmful content, incorrect descriptions or an author’s removal request.

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.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.