
Swift Expert
FreeMaster iOS/macOS development with Swift and SwiftUI.
Free · Opens the source repo
What Swift Expert does
Swift Expert is a comprehensive skill designed for developers working on iOS, macOS, watchOS, and tvOS applications using Swift 5.9 and above. This skill provides a structured workflow that guides users through the essential stages of application development, including architecture analysis, protocol design, implementation, optimization, and testing. With an emphasis on modern Swift features like async/await, actors, and protocol-oriented programming, it equips developers with the tools needed to create efficient, safe, and maintainable code.
The core workflow begins with architecture analysis, helping developers identify platform targets and dependencies while selecting appropriate design patterns. Following this, users are guided to create protocol-first APIs, ensuring type safety and clarity in their code. The implementation phase leverages async/await for asynchronous operations, promoting cleaner and more readable code. Performance optimization is also a key focus, with profiling techniques provided to ensure thread safety and efficient resource usage.
Testing is an integral part of the development process, and Swift Expert emphasizes the importance of writing comprehensive tests using XCTest and async patterns. The skill includes reference guides that cover various topics such as SwiftUI patterns, concurrency management, protocol-oriented design, memory performance, and testing strategies, allowing users to dive deeper into specific areas as needed. Whether you're a seasoned developer or new to Swift, this skill is tailored to enhance your development practices and streamline your workflow.
When to use it
Use Swift Expert when developing applications with Swift 5.9+ that require efficient state management, concurrency handling, and protocol-oriented architecture.
When not to use it
This skill may not be suitable for projects that do not use Swift or are based on older versions of Swift prior to 5.9, or for non-iOS/macOS platforms.
What you can build with it
Building a SwiftUI App
Leverage Swift Expert to implement a SwiftUI application with proper state management and UI patterns.
Implementing Async Features
Use the skill to effectively manage asynchronous operations in your app with async/await.
Designing Protocol-Oriented APIs
Create robust and type-safe APIs using protocol-oriented programming principles guided by the skill.
How to install Swift Expert
View source1. Install with the skills CLI
npx skills add jeffallan/claude-skills/swift-expert --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by jeffallanSwift 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
Frequently asked questions about Swift Expert
Similar skills
Android App Development
Comprehensive guide for Android and cross-platform app development.
Add App Clip to Expo App
Integrate lightweight iOS App Clips into your Expo project.
APK Reverse
Streamline your Android APK reverse engineering process.
React Native Expert
Build and optimize mobile apps with React Native and Expo.
Kotlin Specialist
Master idiomatic Kotlin with expert patterns and practices.
Flutter Expert
Build high-performance cross-platform apps with Flutter.
