swift-concurrency

Installation
SKILL.md

Swift Concurrency

Priority: P0 (CRITICAL)

Write Structured Async Code

  • Async Functions: Mark with async and call with await.
  • async let: Use async let for parallel execution when multiple tasks independent.
  • Task Groups: Use withTaskGroup or withThrowingTaskGroup for spawning dynamic number of tasks.
  • Error Handling: Combine with throws. Always handle CancellationError.

See implementation examples for parallel fetch with async let and Task Groups.

Isolate State with Actors

  • Data Isolation: Use actor for shared mutable state to avoid data races.
  • @MainActor: Annotate UI classes (Views, ViewModels) with @MainActor for main thread execution. Use MainActor.run { ... } for inline UI updates in async blocks.
  • Global Actors: Use @GlobalActor for specific thread-bound resources.
  • nonisolated: Use nonisolated for methods that don't access actor state to avoid unnecessary hops.
Installs
1
GitHub Stars
580
First Seen
Sep 9, 2026