Swift Concurrency

SKILL.md

Swift Concurrency

Priority: P0

Implementation Guidelines

async/await

  • Async Functions: Mark with async, call with await.
  • Error Handling: Combine with throws for async throwing functions.
  • No Completion Handlers: Prefer async over callback-based APIs.

Actors

  • Data Isolation: Use actor for mutable state accessed from multiple tasks.
  • MainActor: Annotate UI code with @MainActor for main thread execution.
  • Actor Isolation: All actor properties/methods are isolated automatically.

Task Management

  • Structured Concurrency: Use Task {}, async let, TaskGroup.
  • Cancellation: Check Task.isCancelled, propagate cancellation.
  • Detached Tasks: Avoid Task.detached unless necessary.

Anti-Patterns

  • Blocking Main Thread: **No synchronous work in @MainActor**: Use Task.
  • Missing MainActor: **UI updates must be @MainActor**: Compiler error.
  • Ignoring Cancellation: **Check Task.isCancelled**: Respect cancellation.

References

Weekly Installs
0
GitHub Stars
339
First Seen
Jan 1, 1970