concurrency-expert
Swift Concurrency review and remediation for Swift 6.2+. Use when asked to review Swift Concurrency usage, improve concurrency compliance, or fix Swift concurrency compiler errors.
What this skill does
# Swift Concurrency Expert
## Overview
Review and fix Swift Concurrency issues in Swift 6.2+ codebases by applying actor isolation, Sendable safety, and modern concurrency patterns with minimal behavior changes.
## Workflow
### 1. Triage the issue
- Capture the exact compiler diagnostics and the offending symbol(s)
- Check project concurrency settings: Swift language version (6.2+), strict concurrency level
- Check if approachable concurrency (default actor isolation / main-actor-by-default) is enabled
- Identify the current actor context (`@MainActor`, `actor`, `nonisolated`)
- Confirm whether the code is UI-bound or intended to run off the main actor
### 2. Apply the smallest safe fix
Prefer edits that preserve existing behavior while satisfying data-race safety.
**Common fixes:**
| Issue | Fix |
|-------|-----|
| UI-bound types | Annotate the type or members with `@MainActor` |
| Protocol conformance on main actor types | Make conformance isolated: `extension Foo: @MainActor SomeProtocol` |
| Global/static state | Protect with `@MainActor` or move into an actor |
| Background work | Use `@concurrent` async function on a `nonisolated` type |
| Sendable errors | Prefer immutable/value types; add `Sendable` only when correct |
## Swift 6.2 Key Changes
### Default Actor Isolation
Swift 6.2 stays single-threaded by default until you choose to introduce concurrency:
```swift
// In Swift 6.2 with approachable concurrency enabled,
// this no longer produces a data race error
@MainActor
final class StickerModel {
let photoProcessor = PhotoProcessor()
func extractSticker(_ item: PhotosPickerItem) async throws -> Sticker? {
guard let data = try await item.loadTransferable(type: Data.self) else {
return nil
}
// Safe - runs on main actor by default
return await photoProcessor.extractSticker(data: data, with: item.itemIdentifier)
}
}
```
### Isolated Conformances
Conformances that need main actor state are now supported:
```swift
protocol Exportable {
func export()
}
// Isolated conformance - safe because compiler ensures
// it's only used on the main actor
extension StickerModel: @MainActor Exportable {
func export() {
photoProcessor.exportAsPNG()
}
}
```
### Protecting Global State
```swift
// Protect with @MainActor
@MainActor
final class StickerLibrary {
static let shared: StickerLibrary = .init()
}
// Or enable main-actor-by-default mode for the whole project
```
### Offloading Work to Background
Use `@concurrent` to explicitly run code on the concurrent thread pool:
```swift
nonisolated struct PhotoProcessor {
@concurrent
func process(data: Data) async -> ProcessedPhoto? {
// Runs on background thread
}
}
// Caller adds await
processedPhotos[item.id] = await PhotoProcessor().process(data: data)
```
## Migration Checklist
1. Check Swift version in build settings (needs 6.2+)
2. Enable approachable concurrency features in build settings
3. Run Swift migration tooling: `swift.org/migration`
4. Fix remaining compiler errors using patterns above
5. Test thoroughly - concurrency bugs may surface at runtime
## Common Patterns
### UI-Bound Class
```swift
@MainActor
final class ViewModel {
var items: [Item] = []
func load() async {
items = try await service.fetchItems()
}
}
```
### Background Processing
```swift
nonisolated struct ImageProcessor {
@concurrent
static func resize(_ image: UIImage, to size: CGSize) async -> UIImage {
// Heavy work runs off main actor
}
}
```
### Actor for Shared Mutable State
```swift
actor Cache {
private var storage: [String: Data] = [:]
func get(_ key: String) -> Data? {
storage[key]
}
func set(_ key: String, value: Data) {
storage[key] = value
}
}
```
## Build Settings
Enable in Xcode under Swift Compiler - Concurrency:
- `SWIFT_STRICT_CONCURRENCY` = complete
- Approachable concurrency features (Swift 6.2+)
Or in Package.swift:
```swift
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
```
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.