/ios-agent-skills:gcd-operationsfrom ios-agent-skills
Diagnoses and resolves iOS/macOS concurrency issues with GCD, locks, and thread safety. Covers deadlocks, thread explosion, data races, DispatchGroup imbalance, timer leaks, lock selection, reader-writer barriers, OperationQueue throttling, and migration to Swift Concurrency.
Ships in ios-agent-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Enterprise-grade concurrency skill for Grand Central Dispatch and OperationQueue. Opinionated: prescribes serial queues by default, target queue hierarchies, labeled queues, NSLock/OSAllocatedUnfairLock for synchronization, barrier-based reader-writer on custom concurrent queues, and OperationQueue for dependency graphs. Apple has not deprecated any core GCD APIs — GCD remains appropriate for parallelism, system I/O, and performance-critical paths. This skill covers correct usage, deadly bug prevention, and coexistence with Swift Concurrency.
Application Layer -> OperationQueue for dependency graphs, cancellation, throttling.
Dispatch Layer -> Serial queues for state protection, concurrent+barrier for R/W.
Synchronization -> NSLock / OSAllocatedUnfairLock for short critical sections.
System I/O -> DispatchSource (timers, file monitoring), DispatchIO (non-blocking file I/O).
Thread Pool -> GCD manages threads. App targets 3-4 well-defined queue subsystems.
Do you need mutual exclusion (protecting shared state)?
+-- YES -> Serial queue (default). Simplest, safest.
+-- NO -> Is this independent parallel work (image processing, batch transforms)?
+-- YES -> Concurrent queue (custom) with barrier for any writes.
+-- NO -> Do you need dependency graphs, cancellation, or throttling?
+-- YES -> OperationQueue with maxConcurrentOperationCount.
+-- NO -> Serial queue. When in doubt, serial.
Which lock?
+-- iOS 16+ -> OSAllocatedUnfairLock (Apple's safe wrapper)
+-- iOS 18+ / Swift 6 -> Mutex from Synchronization framework
+-- Any iOS -> NSLock (safe, simple, recommended by Apple DTS)
NEVER: os_unfair_lock as direct Swift stored property (memory corruption).
NEVER: DispatchSemaphore as a mutex (no priority donation).
Is the user waiting and watching?
+-- Immediate response (animation, touch) -> .userInteractive
+-- User-triggered, blocking progress -> .userInitiated
+-- Long-running with progress bar -> .utility
+-- Invisible to user (prefetch, sync) -> .background
WARNING: .background QoS may be halted entirely in Low Power Mode.
When: First encounter with a codebase using GCD/OperationQueue.
references/deadlocks.md)references/data-races.md)DispatchQueue.global() scattered throughout, many independent queues, no maxConcurrentOperationCount (references/thread-explosion.md)references/thread-safety.md)references/operation-queue.md)refactoring/ directory with per-feature plans and severity-ranked findings (references/refactoring-workflow.md)When: Need concurrent read/exclusive write access to shared state.
queue.sync { return value }queue.async(flags: .barrier) { mutate }references/thread-safety.md)dispatchPrecondition assertions at boundariesDispatchQueue.concurrentPerform under Thread SanitizerWhen: Need OperationQueue with async work (network, disk I/O).
isAsynchronous, isExecuting, isFinished with thread-safe KVO (references/operation-queue.md)super.start() -- it marks the operation finished immediatelyisCancelled at start, call finish() if cancelledfinish() from every completion pathmain() -- cancelled deps satisfy dependencies, they don't blockWhen: Modernizing specific GCD patterns. Not all patterns should migrate.
references/migration.md)DispatchQueue.main.async -> @MainActor, DispatchGroup -> TaskGroup, serial queue -> actorconcurrentPerform, DispatchIO, DispatchSource, concurrent+barrier reader-writerwithCheckedThrowingContinuation -- resume exactly once on every pathDispatchSemaphore.wait() in any async context<critical_rules> Whether reviewing, generating, or refactoring concurrent code, every output must be thread-safe, deadlock-free, and production-ready. ALWAYS:
DispatchQueue with reverse DNS naming including subsystemdefer { group.leave() } immediately after every group.enter()OSAllocatedUnfairLock (iOS 16+), NSLock (any iOS), or Mutex (Swift 6+) for short critical sections -- never os_unfair_lock as a direct stored propertydispatchPrecondition(condition:) before sync dispatch and UI updates[weak self] in repeating timer handlers and stored closuresDispatchSource timers in deinit (resume first if suspended)isAsynchronous, isExecuting, isFinished with KVO in async OperationsmaxConcurrentOperationCount on OperationQueues -- never leave unlimited for blocking workDispatchQueue.main.sync from any code that might run on the main thread<thought> analyzing potential deadlocks, races, and retention.
</critical_rules><fallback_strategies> When fixing concurrency bugs, you may encounter cascading issues. If you fail to fix the same issue twice, break the loop:
sync with async and restructure the call site to use a completion handler or continuation. Why: eliminating sync eliminates the entire deadlock category — async dispatch never blocks the caller.maxConcurrentOperationCount = 4 instead of trying to make GCD limit threads. Why: GCD's thread pool grows unboundedly when work items block — OperationQueue is the only reliable throttle.NSLock protecting a plain property. Why: barrier correctness requires remembering to use the barrier flag on every write and the exact same queue for every access — a lock has a simpler mental model with fewer ways to get wrong.
</fallback_strategies>Before finalizing generated or refactored concurrent code, verify ALL:
[] No deadlock risk -- no sync on main, no nested sync on same queue, no ABBA chains
[] No thread explosion -- maxConcurrentOperationCount set, no scattered global() calls
[] No data races -- shared mutable state protected by queue, lock, or actor
[] Queue labels -- every queue has reverse DNS label with subsystem name
[] Barrier correctness -- barriers on custom concurrent queues only, never global
[] Group balance -- every enter() has defer { group.leave() }
[] Timer safety -- [weak self], cancel in deinit, resume before dealloc if suspended
[] Lock safety -- no os_unfair_lock as stored property, no semaphore as mutex
[] Operation KVO -- async operations override isExecuting/isFinished with thread-safe KVO
[] Main thread -- UI updates verified with dispatchPrecondition(.onQueue(.main))
[] Swift Concurrency coexistence -- no semaphore.wait() in async contexts
[] Background tasks -- endBackgroundTask called on every path
Before refactoring GCD code to Swift Concurrency: load the swift-concurrency skill to understand actor isolation and Sendable constraints. Migration without that context leads to subtle bugs.
| Scenario | Companion skill | Apply when |
|---|---|---|
Migrating GCD patterns to async/await or actors | skills/swift-concurrency/SKILL.md | Converting completion handlers, replacing DispatchQueue with actors, adopting Swift 6 |
| GCD used in UIKit MVVM ViewModels | skills/uikit-mvvm/SKILL.md | Refactoring Massive ViewControllers, extracting ViewModels, setting up Combine bindings |
| Reference | When to Read |
|---|---|
references/rules.md | Do's and Don'ts quick reference: priority rules and critical anti-patterns |
references/queue-creation.md | Queue types, QoS selection, target queue hierarchies, queue labeling |
references/deadlocks.md | The 5 deadlock patterns, prevention with dispatchPrecondition, lock ordering |
references/thread-safety.md | Lock selection (NSLock, OSAllocatedUnfairLock, Mutex), reader-writer barrier, @Atomic trap, singletons |
references/thread-explosion.md | Thread explosion causes, priority inversion, thread starvation, throttling strategies |
references/dispatch-primitives.md | DispatchGroup, DispatchWorkItem, DispatchSemaphore, DispatchSource timers, DispatchIO |
references/operation-queue.md | AsyncOperation base class, KVO state management, cancellation, dependency graphs |
references/data-races.md | Value type COW races, memory management, main thread violations, real-world fixes |
references/debugging.md | Thread Sanitizer, dispatchPrecondition, Instruments, os_signpost, testing strategies |
references/migration.md | GCD to Swift Concurrency mapping, what to migrate vs keep, bridging with continuations |
references/refactoring-workflow.md | refactoring/ directory protocol, per-feature plans, PR sizing, verification checklist |
README.md (opens in a new tab)references/data-races.md (opens in a new tab)references/deadlocks.md (opens in a new tab)references/debugging.md (opens in a new tab)references/dispatch-primitives.md (opens in a new tab)references/migration.md (opens in a new tab)references/operation-queue.md (opens in a new tab)references/queue-creation.md (opens in a new tab)references/refactoring-workflow.md (opens in a new tab)references/rules.md (opens in a new tab)references/thread-explosion.md (opens in a new tab)references/thread-safety.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (rusel95/ios-agent-skills) — no native marketplace selected
npx claudepluginhub p/rusel95-ios-agent-skills11 skills in this plugin
/ios-accessibilityProduction-grade iOS accessibility skill covering VoiceOver, Dynamic Type, color contrast, motion, Switch Control, Voice Control, and WCAG 2.2 compliance for both SwiftUI and UIKit. This skill should be used when creating new iOS screens or views, reviewing existing iOS code for accessibility, adding VoiceOver support, fixing Dynamic Type issues, auditing WCAG compliance, implementing accessibilityLabel/traits/hints, grouping elements for assistive technology, adding custom actions or rotors, respecting system accessibility preferences (reduce motion, increase contrast, differentiate without color), writing accessibility-focused XCTest audits, or preparing apps for enterprise compliance (ADA, EAA, Section 508). Use this skill any time someone is working with iOS accessibility, VoiceOver, Dynamic Type, assistive technology, WCAG mapping, or accessibility modifiers in SwiftUI or UIKit — even if they only say 'make this accessible' or 'add VoiceOver support' or 'check contrast.' Also run an accessibility pass on any newly generated SwiftUI or UIKit view code before finalizing — AI coding assistants systematically produce inaccessible code by default (hardcoded fonts, onTapGesture instead of Button, missing labels, no system preference checks) and this skill corrects those patterns./ios-localizationProduction-grade iOS localization skill covering String Catalogs (.xcstrings), CLDR pluralization, SwiftUI/UIKit localization APIs, RTL layout, date/number/currency formatting, and enterprise patterns (modular apps, white-label, accessibility localization). This skill should be used when creating or editing localized iOS strings, working with .xcstrings or .strings files, implementing pluralization, formatting dates/numbers/currencies for display, building RTL-compatible layouts, localizing accessibility labels, setting up localization in Swift Packages, or reviewing code for localization correctness. Use this skill any time someone is working with iOS localization, i18n, l10n, String Catalogs, plural rules, RTL, date formatting, or translated strings — even if they only say 'add a string' or 'format this date' or 'make this work in Arabic.' Also audit any newly generated user-facing iOS code for localization failures before finalizing — AI coding assistants systematically produce broken localization (hardcoded strings, missing plural categories, wrong date formats, left/right instead of leading/trailing) and this skill corrects those patterns. For .xcstrings files that are too large for direct editing, use the bundled Python scripts in scripts/ to validate, add entries, audit completeness, and fix plural categories programmatically./ios-loggingEnterprise skill for iOS production error observability and logging (iOS 15+, Swift 5.5+). The trigger is OBSERVABILITY intent — the user wants errors captured and visible in production, not just handled. Use when: adding os.Logger or replacing print() with structured logging; setting up or integrating a crash SDK (Sentry, Crashlytics, PostHog); auditing error handling for silent failures (catch blocks with no Logger/ErrorReporter call, try? on network/auth/payment operations, Task {} with no do-catch, Combine .replaceError() killing error visibility); adding privacy annotations to logs; integrating MetricKit for OOM/hang detection; or asking why errors are disappearing silently in production. Also use when reviewing any catch block, try?, or Task {} specifically to ensure errors reach a remote crash reporting service — not just for writing error handling in general./ios-securityUse for any iOS security question — whether you're asking about a specific vulnerability, checking if a pattern is secure, or running a full audit. Triggers on: Keychain vs UserDefaults decisions, ATS/NSAllowsArbitraryLoads configuration, certificate pinning implementation, WebView security (UIWebView, WKWebView), hardcoded secrets or API keys, jailbreak/tamper detection, biometric authentication, MASVS controls, OWASP mobile security, App Store rejection risks, and compliance requirements (HIPAA, PCI DSS, GDPR). Also use when someone asks 'is this secure?', 'what should I use instead?', or 'how do I fix this?' about any iOS storage, network, or cryptography pattern./ios-testingInvoke any time a user is writing iOS/Swift tests or asking why tests behave a certain way — including XCTest versus Swift Testing (@Test/#expect) choices, async ViewModel tests with @Observable or @Published, snapshot testing across device sizes, mocking protocols for dependency injection, setUp/tearDown lifecycle issues, tests that fail on CI but pass locally, flaky async tests, testing VIPER/TCA/MVVM architectures, and coverage gaps on error paths. The trigger is user intent: they are trying to verify, assert, or validate iOS/Swift behavior in a test context, whether they use the word 'testing' or not./swift-concurrencyUse for any Swift Concurrency question on Apple platforms. Triggers on: actor reentrancy (stale state after await), AsyncStream lifecycle (continuation.finish, onTermination), TaskGroup memory and task throttling (activeProcessorCount), Sendable conformance across actor boundaries (non-Sendable third-party types), SWIFT_STRICT_CONCURRENCY=complete error triage ('Sending X risks causing data races'), Swift 6 / 6.2 migration (nonisolated caller-side isolation, @concurrent), cooperative pool blocking, async/await patterns, and continuation misuse. Also covers @MainActor isolation, structured concurrency, and converting callbacks to async/await. Use whenever the query mentions actor, AsyncStream, TaskGroup, Sendable, nonisolated, withCheckedContinuation, or Swift 6.Other plugins' skills for the same job