Skip to content
Back to skills

Swift Concurrency

ASecurity

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/su...

  • 16 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 11, 2026
developmentswiftkotlinreactapi

Works with

  • api

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add TalissonVitorino/kmp-ios-skills --skill swift-concurrency --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Swift Concurrency?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Swift Concurrency
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/talissonvitorino-swift-concurrency/badge)](https://www.skillsdirectory.com/skills/talissonvitorino-swift-concurrency)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.