swift-expert
NewBuilds 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.
Summary
This skill enables Claude to act as a Swift expert for building iOS, macOS, watchOS, and tvOS applications.
- It provides guidance on SwiftUI views and state management, protocol-oriented design, async/await concurrency, actors for thread safety, and debugging Swift-specific issues, making it essential for modern Apple platform development.
Overview
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
Install & Usage
mkdir -p .claude/skillsmkdir -p .claude/skills && curl -o .claude/skills/swift-expert.md https://raw.githubusercontent.com/jeffallan/claude-skills/main/skills/swift-expert/SKILL.md/swift-expertUse Cases
Usage Examples
/swift-expert Build a SwiftUI form with validation using Combine publishers and async/await.
/swift-expert Create a protocol for a cache service with associated types and implement it with actors.
/swift-expert Profile this SwiftUI app with Instruments and fix any thread safety issues.
Security Audits
Frequently Asked Questions
What is swift-expert?
This skill enables Claude to act as a Swift expert for building iOS, macOS, watchOS, and tvOS applications. It provides guidance on SwiftUI views and state management, protocol-oriented design, async/await concurrency, actors for thread safety, and debugging Swift-specific issues, making it essential for modern Apple platform development.
How to install swift-expert?
To install swift-expert: create the skills directory (mkdir -p .claude/skills), then run: mkdir -p .claude/skills && curl -o .claude/skills/swift-expert.md https://raw.githubusercontent.com/jeffallan/claude-skills/main/skills/swift-expert/SKILL.md. Finally, /swift-expert in Claude Code.
What is swift-expert best for?
swift-expert is a skill categorized under General. It is designed for: design. Created by jeffallan.
What can I use swift-expert for?
swift-expert is useful for: Design a protocol-oriented networking layer with async/await and generics for a SwiftUI app.; Implement a SwiftUI view with complex state management using @State, @Binding, and @ObservableObject.; Refactor legacy UIKit code to integrate with SwiftUI using UIHostingController and Combine.; Debug actor isolation and Sendable warnings in a concurrent Swift module.; Optimize memory usage and fix retain cycles in a SwiftUI application using Instruments.; Write comprehensive unit tests for async functions and actors using XCTest..