swift_skill
- Swift
56
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill rshankras/claude-code-apple-skills --skill swift- SKILL.md1.7 KB
Overview
This skill provides practical Swift concurrency patterns for async/await, structured concurrency, actors, continuations, and migration to Swift 6.2 features. It focuses on preventing data races, resolving actor isolation errors, and modernizing legacy callback code to async idioms.
How this skill works
I inspect code, error messages, and the Swift toolchain settings to determine whether issues are compiler-enforced strict concurrency problems or runtime data races. Based on the diagnosis I recommend patterns such as async let, TaskGroup, actors, @MainActor, continuations, and Swift 6.2 @concurrent or isolated conformances, with concrete fixes and migration steps. I also provide a checklist to validate Sendable conformance, cancellation handling, and proper continuation usage.
When to use it
- You have data race runtime crashes or nondeterministic state updates
- Compiler errors about actor isolation or strict concurrency while migrating to Swift 6
- Bridging legacy completion-handler, delegate, or callback APIs to async/await
- Implementing parallel work with async let or TaskGroup for throughput
- Protecting shared mutable state with actors or @MainActor
- Applying Swift 6.2 features like @concurrent or isolated conformances
Best practices
- Prefer structured concurrency (async let, withTaskGroup) over unstructured Task {} for lifecycle safety
- Protect shared mutable state with actors rather than locks or ad-hoc DispatchQueues
- Mark UI-bound types @MainActor and avoid blocking work on the main actor; use await for long-running tasks
- Ensure types crossing actor boundaries conform to Sendable or isolate data access
- Handle Task cancellation explicitly (Task.isCancelled / Task.checkCancellation())
- Use withCheckedContinuation and AsyncStream carefully: resume exactly once and wire cancellation/cleanup paths
Example use cases
- Fixing actor isolation compiler errors when migrating code to Swift 6 strict checking
- Converting delegate-based networking or location APIs to async/await using withCheckedContinuation or AsyncStream
- Running many independent network calls in parallel with withTaskGroup and aggregating results safely
- Protecting shared cache or token storage by moving state into an actor and eliminating data races
- Adopting Swift 6.2 @concurrent to offload CPU-bound work while keeping clear isolation semantics
FAQ
Use actor for general shared mutable state; use @MainActor for UI-bound state or types that must run on the main thread. Prefer actors for thread-safety and map UI updates to @MainActor when updating views.
When should I use withCheckedContinuation vs AsyncStream?
Use withCheckedContinuation to bridge single-callback APIs into async functions. Use AsyncStream when the API delivers a sequence of values (delegates, events) or when you need buffered/asynchronous iteration.