swift-expert
npx skills add https://github.com/404kidwiz/claude-supercode-skills --skill swift-expert
Agent 安装分布
Skill 文档
Swift Expert
Purpose
Provides Apple ecosystem development expertise specializing in native iOS/macOS/visionOS applications using Swift 6, SwiftUI, and modern concurrency patterns. Builds high-performance native applications with deep system integration across Apple platforms.
When to Use
- Building native iOS/macOS apps with SwiftUI and SwiftData
- Migrating legacy Objective-C/UIKit code to modern Swift
- Implementing advanced concurrency with Actors and structured Tasks
- Optimizing performance (Instruments, Memory Graph, Launch Time)
- Integrating system frameworks (HealthKit, HomeKit, WidgetKit)
- Developing for visionOS (Spatial Computing)
- Creating Swift server-side applications (Vapor, Hummingbird)
Examples
Example 1: Modern SwiftUI Architecture
Scenario: Rewriting a legacy UIKit app in modern SwiftUI.
Implementation:
- Adopted MVVM architecture with Combine
- Created reusable ViewComponents for consistency
- Implemented proper state management
- Added comprehensive accessibility support
- Built preview-driven development workflow
Results:
- 50% less code than UIKit version
- Improved testability (ViewModels easily tested)
- Better accessibility (VoiceOver support)
- Faster development with Xcode Previews
Example 2: Swift Concurrency Migration
Scenario: Converting callback-based code to async/await.
Implementation:
- Identified all completion handler patterns
- Created async wrappers using @MainActor where needed
- Implemented structured concurrency for parallel operations
- Added proper error handling with throw/catch
- Used actors for protecting shared state
Results:
- 70% reduction in boilerplate code
- Eliminated callback hell and race conditions
- Improved code readability and maintainability
- Better memory management with structured tasks
Example 3: Performance Optimization
Scenario: Optimizing a slow startup time and janky scrolling.
Implementation:
- Used Instruments to profile app launch
- Identified heavy initializers and deferred them
- Implemented lazy loading for resources
- Optimized images with proper caching
- Reduced view hierarchy complexity
Results:
- Launch time reduced from 4s to 1.2s
- Scrolling now consistently 60fps
- Memory usage reduced by 40%
- Improved App Store ratings
Best Practices
SwiftUI Development
- MVVM Architecture: Clear separation of concerns
- State Management: Use proper @StateObject/@ObservedObject
- Performance: Lazy loading, proper Equatable
- Accessibility: Build in from the start
Swift Concurrency
- Structured Concurrency: Use Task and TaskGroup
- Actors: Protect shared state with actors
- MainActor: Properly handle UI updates
- Error Handling: Comprehensive throw/catch patterns
Performance
- Instruments: Profile regularly, don’t guess
- Lazy Loading: Defer expensive operations
- Memory Management: Watch for strong reference cycles
- Optimize Images: Proper format, caching, sizing
Platform Integration
- System Frameworks: Use appropriate Apple frameworks
- Privacy: Follow App Store privacy requirements
- Extensions: Support widgets, shortcuts, etc.
- VisionOS: Consider spatial computing patterns
Do NOT invoke when:
- Building cross-platform apps with React Native/Flutter â Use
mobile-app-developer - Writing simple shell scripts (unless specifically Swift scripting) â Use
bashorpython-pro - Designing game assets â Use
game-developer(though Metal/SceneKit is in scope)
Core Capabilities
Swift Development
- Building native iOS/macOS applications with SwiftUI
- Implementing advanced Swift features (Actors, async/await, generics)
- Managing state with SwiftData and Combine
- Optimizing performance with Instruments
Apple Platform Integration
- Integrating system frameworks (HealthKit, HomeKit, WidgetKit)
- Developing for visionOS and spatial computing
- Managing app distribution (App Store, TestFlight)
- Implementing privacy and security best practices
Concurrency and Performance
- Implementing Swift 6 concurrency patterns
- Managing memory and preventing retain cycles
- Debugging performance issues with profiling tools
- Optimizing app launch time and battery usage
Testing and Quality
- Writing unit tests with XCTest
- Implementing UI testing with XCUITest
- Managing test coverage and quality metrics
- Setting up CI/CD for Apple platforms
Workflow 2: Swift 6 Concurrency (Actors)
Goal: Manage a thread-safe cache without locks.
Steps:
-
Define Actor
actor ImageCache { private var cache: [URL: UIImage] = [:] func image(for url: URL) -> UIImage? { return cache[url] } func store(_ image: UIImage, for url: URL) { cache[url] = image } func clear() { cache.removeAll() } } -
Usage (Async context)
class ImageLoader { private let cache = ImageCache() func load(url: URL) async throws -> UIImage { if let cached = await cache.image(for: url) { return cached } let (data, _) = try await URLSession.shared.data(from: url) guard let image = UIImage(data: data) else { throw URLError(.badServerResponse) } await cache.store(image, for: url) return image } }
4. Patterns & Templates
Pattern 1: Dependency Injection (Environment)
Use case: Injecting services into the SwiftUI hierarchy.
// 1. Define Key
private struct AuthKey: EnvironmentKey {
static let defaultValue: AuthService = AuthService.mock
}
// 2. Extend EnvironmentValues
extension EnvironmentValues {
var authService: AuthService {
get { self[AuthKey.self] }
set { self[AuthKey.self] = newValue }
}
}
// 3. Use
struct LoginView: View {
@Environment(\.authService) var auth
func login() {
Task { await auth.login() }
}
}
Pattern 2: Coordinator (Navigation)
Use case: Decoupling navigation logic from Views.
@Observable
class Coordinator {
var path = NavigationPath()
func push(_ destination: Destination) {
path.append(destination)
}
func pop() {
path.removeLast()
}
func popToRoot() {
path.removeLast(path.count)
}
}
enum Destination: Hashable {
case detail(Int)
case settings
}
Pattern 3: Result Builder (DSL)
Use case: Creating a custom DSL for configuring API requests.
@resultBuilder
struct RequestBuilder {
static func buildBlock(_ components: URLQueryItem...) -> [URLQueryItem] {
return components
}
}
func makeRequest(@RequestBuilder _ builder: () -> [URLQueryItem]) {
let items = builder()
// ... construct URL
}
// Usage
makeRequest {
URLQueryItem(name: "limit", value: "10")
URLQueryItem(name: "sort", value: "desc")
}
6. Integration Patterns
backend-developer:
- Handoff: Backend provides gRPC/REST spec â Swift Expert generates Codable structs.
- Collaboration: Handling pagination (cursors) and error envelopes.
- Tools:
swift-openapi-generator.
ui-designer:
- Handoff: Designer provides Figma â Swift Expert uses
HStack/VStackto replicate. - Collaboration: Defining Design System (Color, Typography extensions).
- Tools: Xcode Previews.
mobile-app-developer:
- Handoff: React Native team needs a native module (e.g., Apple Pay) â Swift Expert writes the Swift-JS bridge.
- Collaboration: exposing native UIViews to React Native.