swift-concurrency
Installation
SKILL.md
Swift Concurrency Best Practices (Swift 6+)
1. Structured Concurrency
- Prefer
async letfor parallel tasks when the number of tasks is known. - Use
TaskGroupfor a dynamic number of parallel tasks. - Avoid
Task { ... }(unstructured) unless bridging from synchronous code (e.g., UI event handlers) or firing background work that outlives the scope.
2. Actors & Isolation
- Default to
@MainActorfor all UI-related classes (ViewModels, SwiftUI Views). - Use
actorfor shared mutable state that is not UI-related (e.g., caching, database managers). - Global Actors: Use
@MainActoror custom global actors to synchronize access across different types.