ios-concurrency

Advises on iOS and macOS concurrency using Swift Concurrency, GCD, Combine, and OperationQueue.

5|Updated Sep 24, 2017
One-click install
npx skills add https://github.com/madyankin/dotfiles --skill ios-concurrency-madyankin
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: ios-concurrency
Source: https://github.com/madyankin/dotfiles/tree/main/.config/agents/skills/ios-concurrency
Command: npx skills add https://github.com/madyankin/dotfiles --skill ios-concurrency-madyankin

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Choosing and correctly implementing the right concurrency model on iOS/macOS is error-prone: data races, deadlocks, actor reentrancy bugs, and thread explosion are common. This Skill provides expert guidance across all Apple concurrency layers so you can write correct, performant concurrent Swift code. ## Core Features & Use Cases - Swift Concurrency guidance: async/await, structured concurrency with async let and TaskGroup, actors, MainActor, Sendable conformance, continuations, and cancellation. - GCD and legacy coverage: DispatchQueue, barriers, semaphores, DispatchGroup, DispatchSource, OperationQueue dependency graphs, Thread, RunLoop, and locking primitives. - Combine pipelines: publishers, subjects, operators, schedulers, backpressure, and interop with async/await. - Diagnosis and migration: Thread Sanitizer, Instruments Swift Concurrency template, deadlock checklists, and GCD-to-Swift-Concurrency migration patterns. - Use Case: You are migrating a UIKit app from completion-handler networking to async/await and need to wrap URLSession callbacks with withCheckedThrowingContinuation, protect a shared cache with an actor, and update the UI on MainActor. ## Quick Start Ask how to safely migrate a DispatchQueue-based cache to a Swift actor, or how to fix a data race reported by Thread Sanitizer.

Frequently Asked Questions about ios-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate from GCD to Swift Concurrency?▼

Replace serial DispatchQueues protecting state with actors, convert completion handlers to async throws functions using withCheckedThrowingContinuation, and replace DispatchGroup with async let or TaskGroup. Migrate leaf operations first, then their callers.

What is actor reentrancy in Swift and why does it cause bugs?▼

Actor reentrancy means another task can run on the same actor while a suspended task waits at an await, so state can change across suspension points. Fix it by completing state mutations before awaiting or re-checking invariants after each await.

Should I use Combine or async/await for new iOS code?▼

For new code on iOS 15+, prefer Swift Concurrency with async/await. Keep Combine for existing pipelines, complex operator chains like debounce and zip, and SwiftUI's @Published bindings, and bridge between them using publisher.values.

Why does DispatchQueue.sync cause a deadlock?▼

Calling sync on a serial queue from within that same queue blocks the queue waiting for itself, causing a deadlock. The same happens when calling sync on the main queue from the main thread, or when two queues synchronously wait on each other.

How do I detect data races in Swift code?▼

Enable Thread Sanitizer in Xcode's scheme diagnostics to catch races at runtime, and turn on strict concurrency checking in build settings to surface Sendable and isolation violations at compile time. Swift 6 makes data races compile errors by default.

When should I use OperationQueue instead of TaskGroup?▼

Use OperationQueue when you need dependency graphs between operations, KVO-observable state, or integration with existing NSOperation-based code. For new code, TaskGroup with structured concurrency is preferred for parallel work with cancellation propagation.