home / skills / 404kidwiz / claude-supercode-skills / swift-expert-skill

swift-expert-skill skill

/swift-expert-skill

This skill helps you master Swift ecosystem native app development with modern concurrency, SwiftUI, and deep system integration across Apple platforms.

npx playbooks add skill 404kidwiz/claude-supercode-skills --skill swift-expert-skill

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
7.8 KB
---
name: swift-expert
description: Expert in the Swift ecosystem, specializing in iOS/macOS/visionOS development, Swift 6 concurrency, and deep system integration.
---

# 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:**
1. Adopted MVVM architecture with Combine
2. Created reusable ViewComponents for consistency
3. Implemented proper state management
4. Added comprehensive accessibility support
5. 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:**
1. Identified all completion handler patterns
2. Created async wrappers using @MainActor where needed
3. Implemented structured concurrency for parallel operations
4. Added proper error handling with throw/catch
5. 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:**
1. Used Instruments to profile app launch
2. Identified heavy initializers and deferred them
3. Implemented lazy loading for resources
4. Optimized images with proper caching
5. 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 `bash` or `python-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:**

1.  **Define Actor**
    ```swift
    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()
        }
    }
    ```

2.  **Usage (Async context)**
    ```swift
    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.

```swift
// 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.

```swift
@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.

```swift
@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/VStack` to 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.

---

Overview

This skill provides expert guidance and hands-on patterns for building native Apple platform apps using Swift 6, SwiftUI, and modern concurrency. It focuses on high-performance implementations, deep system integration across iOS/macOS/visionOS, and practical migration from legacy code. The content emphasizes reusable architecture, profiling-driven optimization, and secure platform integration.

How this skill works

The skill inspects app architecture, concurrency hotspots, memory and launch-time profiles, and integration boundaries with system frameworks. It prescribes concrete refactors: adopt MVVM and Environment-based dependency injection, migrate callbacks to async/await and Actors, and apply Instruments-driven optimizations. It also supplies patterns for navigation coordinators, caching actors, and Swift-specific DSLs or result builders for cleaner APIs.

When to use it

  • Rewriting UIKit/Objective-C apps to SwiftUI and SwiftData
  • Migrating completion-handler logic to structured concurrency (async/await, Task, Actors)
  • Resolving startup latency, memory leaks, or janky scrolling using Instruments
  • Integrating Apple frameworks (HealthKit, HomeKit, WidgetKit) or building visionOS spatial experiences
  • Setting up testing, CI/CD, or App Store distribution workflows

Best practices

  • Adopt MVVM and isolate side effects in ViewModels for testability
  • Use structured concurrency and Actors to avoid race conditions; mark UI updates with @MainActor
  • Profile with Instruments early and defer expensive initializers using lazy loading
  • Inject services via EnvironmentKeys for decoupling and easier testing
  • Build accessibility and privacy considerations into features from day one

Example use cases

  • Rewrite a legacy UIKit app into SwiftUI with MVVM, reusable components, and preview-driven workflows
  • Migrate a network layer from callbacks to async/await, using TaskGroup for parallel loads and Actors for shared caches
  • Optimize app launch: profile with Instruments, defer heavy work, reduce view hierarchy and improve image caching to cut launch time and memory use
  • Implement a thread-safe image cache with an Actor and integrate it into an async image loader
  • Create a Coordinator pattern to centralize navigation and keep Views declarative and lightweight

FAQ

Will this skill help migrate large Objective-C codebases to Swift?

Yes. It provides architecture patterns, incremental migration strategies, and practical examples for wrapping or replacing Objective-C components.

Can it guide visionOS development and spatial UI patterns?

Yes. It covers visionOS-specific considerations, spatial computing patterns, and how to map existing UI concepts to three-dimensional experiences.