swift-expert
jeffallan/claude-skills
Expert Swift development for iOS/macOS with SwiftUI, async/await, and protocol-oriented architecture.
What is swift-expert?
Builds production iOS, macOS, watchOS, and tvOS applications using Swift 5.9+. Handles SwiftUI state management, async/await concurrency, actor-based thread safety, and protocol-oriented design. Use when developing native Apple platform apps or server-side Swift with Vapor.
- Designs protocol-first APIs with associated types and generics
- Implements SwiftUI views with @Observable state management (Swift 5.9+)
- Handles async/await concurrency and structured concurrency patterns
- Implements actors for thread-safe mutable state
- Debugs Swift-specific issues including actor isolation and Sendable compliance
- Integrates UIKit, Combine, and Vapor frameworks
How to install swift-expert
npx skills add https://github.com/jeffallan/claude-skills --skill swift-expertHow to use swift-expert
- 1.Analyze your project architecture and identify platform targets
- 2.Define capability protocols with associated types as your API contracts
- 3.Implement concrete types using structs/enums with value semantics
- 4.Use async/await for all asynchronous operations and actors for shared mutable state
- 5.Run `swift build -warnings-as-errors` to verify actor isolation and Sendable compliance
- 6.Write comprehensive XCTest tests including async test patterns
- 7.Profile with Instruments before optimizing performance
Use cases
- Building iOS/macOS applications with SwiftUI and modern concurrency
- Designing thread-safe caching layers using actors
- Migrating from ObservableObject to @Observable in Swift 5.9+
- Implementing protocol-oriented repositories and dependency injection
- Server-side Swift development with Vapor and async/await
- iOS/macOS developers
- Swift backend engineers
- Developers migrating to async/await
- Teams adopting protocol-oriented architecture
- Developers building cross-platform Apple apps
swift-expert FAQ
Use @Observable (Swift 5.9+) for new code—it eliminates boilerplate and works seamlessly with SwiftUI. Only use ObservableObject when supporting older Swift versions.
Use actors to isolate mutable state. The compiler enforces actor isolation rules and prevents data races. Avoid manual locking with NSLock.
Prefer structs and enums (value types) by default. Use classes only when you need reference semantics or Objective-C interoperability.
async/await provides structured concurrency, better error handling, and cleaner syntax. Use async/await for all new code; only use completion handlers when wrapping legacy APIs.
Run `swift build -warnings-as-errors` to surface Sendable violations. Mark types with `Sendable` and ensure all captured values in closures are thread-safe.
Full instructions (SKILL.md)
Source of truth, from jeffallan/claude-skills.
name: swift-expert description: Builds iOS/macOS/watchOS/tvOS applications, implements SwiftUI views and state management, designs protocol-oriented architectures, handles async/await concurrency, implements actors for thread safety, and debugs Swift-specific issues. Use when building iOS/macOS applications with Swift 5.9+, SwiftUI, or async/await concurrency. Invoke for protocol-oriented programming, SwiftUI state management, actors, server-side Swift, UIKit integration, Combine, or Vapor. license: MIT metadata: author: https://github.com/Jeffallan version: "1.1.0" domain: language triggers: Swift, SwiftUI, iOS development, macOS development, async/await Swift, Combine, UIKit, Vapor role: specialist scope: implementation output-format: code related-skills:
Swift Expert
Core Workflow
- Architecture Analysis - Identify platform targets, dependencies, design patterns
- Design Protocols - Create protocol-first APIs with associated types
- Implement - Write type-safe code with async/await and value semantics
- Optimize - Profile with Instruments, ensure thread safety
- Test - Write comprehensive tests with XCTest and async patterns
Validation checkpoints: After step 3, run
swift buildto verify compilation. After step 4, runswift build -warnings-as-errorsto surface actor isolation and Sendable warnings. After step 5, runswift testand confirm all async tests pass.
Reference Guide
Load detailed guidance based on context:
| Topic | Reference | Load When |
|---|---|---|
| SwiftUI | references/swiftui-patterns.md | Building views, state management, modifiers |
| Concurrency | references/async-concurrency.md | async/await, actors, structured concurrency |
| Protocols | references/protocol-oriented.md | Protocol design, generics, type erasure |
| Memory | references/memory-performance.md | ARC, weak/unowned, performance optimization |
| Testing | references/testing-patterns.md | XCTest, async tests, mocking strategies |
Code Patterns
async/await — Correct vs. Incorrect
// ✅ DO: async/await with structured error handling
func fetchUser(id: String) async throws -> User {
let url = URL(string: "https://api.example.com/users/\(id)")!
let (data, _) = try await URLSession.shared.data(from: url)
return try JSONDecoder().decode(User.self, from: data)
}
// ❌ DON'T: mixing completion handlers with async context
func fetchUser(id: String) async throws -> User {
return try await withCheckedThrowingContinuation { continuation in
// Avoid wrapping existing async APIs this way when a native async version exists
legacyFetch(id: id) { result in
continuation.resume(with: result)
}
}
}
SwiftUI State Management
// ✅ DO: use @Observable (Swift 5.9+) for view models
@Observable
final class CounterViewModel {
var count = 0
func increment() { count += 1 }
}
struct CounterView: View {
@State private var vm = CounterViewModel()
var body: some View {
VStack {
Text("\(vm.count)")
Button("Increment", action: vm.increment)
}
}
}
// ❌ DON'T: reach for ObservableObject/Published when @Observable suffices
class LegacyViewModel: ObservableObject {
@Published var count = 0 // Unnecessary boilerplate in Swift 5.9+
}
Protocol-Oriented Architecture
// ✅ DO: define capability protocols with associated types
protocol Repository<Entity> {
associatedtype Entity: Identifiable
func fetch(id: Entity.ID) async throws -> Entity
func save(_ entity: Entity) async throws
}
struct UserRepository: Repository {
typealias Entity = User
func fetch(id: UUID) async throws -> User { /* … */ }
func save(_ user: User) async throws { /* … */ }
}
// ❌ DON'T: use classes as base types when a protocol fits
class BaseRepository { // Avoid class inheritance for shared behavior
func fetch(id: UUID) async throws -> Any { fatalError("Override required") }
}
Actor for Thread Safety
// ✅ DO: isolate mutable shared state in an actor
actor ImageCache {
private var cache: [URL: UIImage] = [:]
func image(for url: URL) -> UIImage? { cache[url] }
func store(_ image: UIImage, for url: URL) { cache[url] = image }
}
// ❌ DON'T: use a class with manual locking
class UnsafeImageCache {
private var cache: [URL: UIImage] = [:]
private let lock = NSLock() // Error-prone; prefer actor isolation
func image(for url: URL) -> UIImage? {
lock.lock(); defer { lock.unlock() }
return cache[url]
}
}
Constraints
MUST DO
- Use type hints and inference appropriately
- Follow Swift API Design Guidelines
- Use
async/awaitfor asynchronous operations (see pattern above) - Ensure
Sendablecompliance for concurrency - Use value types (
struct/enum) by default - Document APIs with markup comments (
/// …) - Use property wrappers for cross-cutting concerns
- Profile with Instruments before optimizing
MUST NOT DO
- Use force unwrapping (
!) without justification - Create retain cycles in closures
- Mix synchronous and asynchronous code improperly
- Ignore actor isolation warnings
- Use implicitly unwrapped optionals unnecessarily
- Skip error handling
- Use Objective-C patterns when Swift alternatives exist
- Hardcode platform-specific values
Output Templates
When implementing Swift features, provide:
- Protocol definitions and type aliases
- Model types (structs/classes with value semantics)
- View implementations (SwiftUI) or view controllers
- Tests demonstrating usage
- Brief explanation of architectural decisions
Related skills
More from jeffallan/claude-skills and the wider catalog.

terraform-engineer
Senior Terraform engineer for infrastructure as code across AWS, Azure, and GCP with modular design and state management.

test-master
Comprehensive testing specialist for unit, integration, E2E, performance, and security tests.

the-fool
Play devil's advocate with structured critical reasoning to stress-test ideas, plans, and decisions.

typescript-pro
Advanced TypeScript type systems, branded types, and tRPC end-to-end type safety for complex applications.

vue-expert
Vue 3 Composition API specialist for components, Nuxt SSR/SSG, Pinia state, and mobile apps.

vue-expert-js
Build Vue 3 apps in JavaScript with JSDoc typing—no TypeScript required.