Skip to main content
skill CX Codex

swift-expert · personamanagmentlayer — Claude Code skill for Swift development

swift-expert guides an agent through Swift work for iOS and macOS, from SwiftUI screens to async code. Use it when a task involves Combine or modern Swift features.

Apache-2.0 163 installs ★ 45 updated 2026-10-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add personamanagmentlayer/pcl --skill swift-expert -a claude-code
Open on GitHub

What swift-expert does

The skill covers Swift 5.9+ topics such as async/await, actors, closures, protocols, and value versus reference types. Its SwiftUI guidance includes view state, composition, navigation, and animation.

Examples in the skill cover Combine-based view models, URLSession networking, and JSON decoding. The agent can use Read, Write, and Edit, along with swift and xcodebuild commands; its permitted tools are limited to that set.

What it helps with

  • build a SwiftUI screen with managed state
  • write an asynchronous Swift API request
  • set up reactive search with Combine
  • understand Swift closures, protocols, and types

Example prompts for the agent

  • Create a SwiftUI profile screen with loading and error states.
  • Write a Swift API client using async/await and JSON decoding.
  • Show how to implement text search with Combine.

How to install swift-expert

1Skills CLI (Vercel)

npx skills add personamanagmentlayer/pcl --skill swift-expert -a claude-code

2Manually: put the files in place

~/.claude/skills/swift-expert/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/swift-expert/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about swift-expert

How do I install swift-expert in Claude Code?

Run npx skills add personamanagmentlayer/pcl --skill swift-expert -a claude-code. The skill file is placed at ~/.claude/skills/swift-expert/SKILL.md.

What does swift-expert do?

It guides Swift development for iOS and macOS, including SwiftUI, Combine, concurrency, and networking.

Which tools can the skill use?

It can use Read, Write, and Edit, plus the swift and xcodebuild commands.

Source text

SKILL.md · Apache-2.0
---
name: swift-expert
version: 1.1.0
description: >-
  Expert-level Swift development for iOS, macOS with SwiftUI, Combine, and modern Swift
  5.9+. Use when the user mentions iOS, macOS, SwiftUI, Combine, async await, or Apple
  platforms, or when the task involves Modern Swift Features, Basics and Optionals,
  Functions and Closures, or Structs and Classes.
category: languages
tags: [swift, ios, macos, swiftui, combine, async-await, apple]
allowed-tools:
  - Read
  - Write
  - Edit
  - Bash(swift:*, xcodebuild:*)
---

# Swift Expert

Expert guidance for Swift development including iOS/macOS apps, SwiftUI, Combine, async/await, and Swift 5.9+ features.

## Core Concepts

### Modern Swift Features (5.9+)

- Async/await concurrency
- Actors for thread safety
- Property wrappers
- Result builders
- Protocols and generics
- Value types vs reference types
- Automatic Reference Counting (ARC)
- Macros (Swift 5.9+)

### SwiftUI

- Declarative UI framework
- State management
- View composition
- Layout system
- Animations
- Navigation

### Combine

- Reactive programming
- Publishers and subscribers
- Operators
- Error handling

## SwiftUI

### Basic Views

```swift
import SwiftUI

struct ContentView: View {
    @State private var name = ""
    @State private var count = 0

    var body: some View {
        VStack(spacing: 20) {
            Text("Hello, \(name.isEmpty ? "World" : name)!")
                .font(.title)
                .foregroundColor(.blue)

            TextField("Enter name", text: $name)
                .textFieldStyle(.roundedBorder)
                .padding()

            HStack {
                Button("Decrement") {
                    count -= 1
                }

                Text("\(count)")
                    .frame(minWidth: 50)

                Button("Increment") {
                    count += 1
                }
            }
            .buttonStyle(.borderedProminent)
        }
        .padding()
    }
}
```

### State Management

```swift
// @State - local view state
struct CounterView: View {
    @State private var count = 0

    var body: some View {
        Button("Count: \(count)") {
            count += 1
        }
    }
}

// @Binding - pass state reference
struct ChildView: View {
    @Binding var isOn: Bool

    var body: some View {
        Toggle("Setting", isOn: $isOn)
    }
}

// @ObservableObject - external state
class UserViewModel: ObservableObject {
    @Published var user: User?
    @Published var isLoading = false
    @Published var error: Error?

    func fetchUser() async {
        isLoading = true
        defer { isLoading = false }

        do {
            user = try await APIClient.shared.fetchUser()
        } catch {
            self.error = error
        }
    }
}

struct UserView: View {
    @StateObject private var viewModel = UserViewModel()

    var body: some View {
        Group {
            if viewModel.isLoading {
                ProgressView()
            } else if let user = viewModel.user {
                UserDetailView(user: user)
            } else if let error = viewModel.error {
                ErrorView(error: error)
            }
        }
        .task {
            await viewModel.fetchUser()
        }
    }
}

// @EnvironmentObject - app-wide state
@main
struct MyApp: App {
    @StateObject private var appState = AppState()

    var body: some Scene {
        WindowGroup {
            ContentView()
                .environmentObject(appState)
        }
    }
}

struct SomeView: View {
    @EnvironmentObject var appState: AppState

    var body: some View {
        Text(appState.currentUser?.name ?? "Guest")
    }
}
```

### Lists and Navigation

```swift
struct PostListView: View {
    let posts: [Post]
    @State private var selectedPost: Post?

    var body: some View {
        NavigationStack {
            List(posts) { post in
                NavigationLink(value: post) {
                    VStack(alignment: .leading) {
                        Text(post.title)
                            .font(.headline)
                        Text(post.excerpt)
                            .font(.subheadline)
                            .foregroundColor(.secondary)
                    }
                }
            }
            .navigationTitle("Posts")
            .navigationDestination(for: Post.self) { post in
                PostDetailView(post: post)
            }
        }
    }
}
```

### Custom Modifiers

```swift
struct CardModifier: ViewModifier {
    func body(content: Content) -> some View {
        content
            .padding()
            .background(Color.white)
            .cornerRadius(10)
            .shadow(radius: 5)
    }
}

extension View {
    func cardStyle() -> some View {
        modifier(CardModifier())
    }
}

// Usage
Text("Hello")
    .cardStyle()
```

## Networking

```swift
actor APIClient {
    static let shared = APIClient()

    private let baseURL = URL(string: "https://api.example.com")!
    private let decoder: JSONDecoder = {
        let decoder = JSONDecoder()
        decoder.keyDecodingStrategy = .convertFromSnakeCase
        return decoder
    }()

    func fetch<T: Decodable>(_ endpoint: String) async throws -> T {
        let url = baseURL.appendingPathComponent(endpoint)
        let (data, response) = try await URLSession.shared.data(from: url)

        guard let httpResponse = response as? HTTPURLResponse,
              (200...299).contains(httpResponse.statusCode) else {
            throw APIError.invalidResponse
        }

        return try decoder.decode(T.self, from: data)
    }

    func post<T: Encodable, R: Decodable>(
        _ endpoint: String,
        body: T
    ) async throws -> R {
        var request = URLRequest(url: baseURL.appendingPathComponent(endpoint))
        request.httpMethod = "POST"
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.httpBody = try JSONEncoder().encode(body)

        let (data, _) = try await URLSession.shared.data(for: request)
        return try decoder.decode(R.self, from: data)
    }
}

enum APIError: LocalizedError {
    case invalidResponse
    case decodingError

    var errorDescription: String? {
        switch self {
        case .invalidResponse:
            return "Invalid server response"
        case .decodingError:
            return "Failed to decode response"
        }
    }
}
```

## Combine Framework

```swift
import Combine

class SearchViewModel: ObservableObject {
    @Published var searchText = ""
    @Published var results: [SearchResult] = []
    @Published var isLoading = false

    private var cancellables = Set<AnyCancellable>()

    init() {
        $searchText
            .debounce(for: .milliseconds(300), scheduler: DispatchQueue.main)
            .removeDuplicates()
            .sink { [weak self] text in
                self?.performSearch(text)
            }
            .store(in: &cancellables)
    }

    private func performSearch(_ text: String) {
        guard !text.isEmpty else {
            results = []
            return
        }

        isLoading = true

        Task {
            do {
                let searchResults: [SearchResult] = try await APIClient.shared
                    .fetch("search?q=\(text)")
                await MainActor.run {
                    self.results = searchResults
                    self.isLoading = false
                }
            } catch {
                await MainActor.run {
                    self.isLoading = false
                }
            }
        }
    }
}
```

## Testing

```swift
import XCTest
@testable import MyApp

final class UserViewModelTests: XCTestCase {
    var viewModel: UserViewModel!
    var mockAPIClient: MockAPIClient!

    override func setUp() {
        super.setUp()
        mockAPIClient = MockAPIClient()
        viewModel = UserViewModel(apiClient: mockAPIClient)
    }

    func testFetchUserSuccess() async throws {
        // Given
        let expectedUser = User(id: UUID(), name: "Alice", email: "[email protected]")
        mockAPIClient.userToReturn = expectedUser

        // When
        await viewModel.fetchUser()

        // Then
        XCTAssertEqual(viewModel.user?.name, "Alice")
        XCTAssertNil(viewModel.error)
        XCTAssertFalse(viewModel.isLoading)
    }

    func testFetchUserFailure() async {
        // Given
        mockAPIClient.shouldFail = true

        // When
        await viewModel.fetchUser()

        // Then
        XCTAssertNil(viewModel.user)
        XCTAssertNotNil(viewModel.error)
        XCTAssertFalse(viewModel.isLoading)
    }
}

// Mock
class MockAPIClient {
    var userToReturn: User?
    var shouldFail = false

    func fetchUser() async throws -> User {
        if shouldFail {
            throw APIError.invalidResponse
        }
        return userToReturn ?? User(id: UUID(), name: "Test", email: "[email protected]")
    }
}
```

## Best Practices

### Code Organization

- Use MVVM pattern for SwiftUI
- Separate business logic from views
- Use dependency injection
- Keep views small and composable

### Memory Management

- Understand ARC (Automatic Reference Counting)
- Use weak references for delegates
- Break retain cycles with [weak self] or [unowned self]
- Use actors for mutable shared state

### Performance

- Use lazy loading where appropriate
- Avoid unnecessary view updates
- Profile with Instruments
- Use value types (structs) by default

### Swift Concurrency

- Prefer async/await over completion handlers
- Use actors for thread-safe mutable state
- Use @MainActor for UI updates
- Avoid blocking the main thread

## Anti-Patterns to Avoid

❌ **Force unwrapping**: Use optional binding instead
❌ **Massive view controllers**: Extract logic to view models
❌ **Strong reference cycles**: Use weak/unowned references
❌ **Blocking main thread**: Use async/await
❌ **Ignoring memory warnings**: Handle memory pressure
❌ **Not using guard**: Use guard for early exits
❌ **Implicit unwrapping**: Prefer explicit optionals

## Reference Documentation

Detailed material lives alongside this skill and is read on demand:

- [Swift Syntax](references/SWIFT_SYNTAX.md) — Basics and Optionals, Functions and Closures, Structs and Classes, Enums, Async/Await (Swift 5.5+), Actors (Thread Safety)

## Resources

- Swift Documentation: https://swift.org/documentation/
- SwiftUI Tutorials: https://developer.apple.com/tutorials/swiftui
- WWDC Sessions: https://developer.apple.com/videos/
- Swift by Sundell: https://www.swiftbysundell.com/
- Hacking with Swift: https://www.hackingwithswift.com/

© personamanagmentlayer · Apache-2.0 · personamanagmentlayer/pcl

Similar skills

All skills for Programming languages →

swift-expert by other authors comes first.

swift-expert https://github.com/Jeffallan swift-expert — a Swift skill that walks the agent through architecture, SwiftUI state, async/await and actors, with build checks in between. Built for iOS and macOS work. CX Codex +1 4,500installs ios-swift-development aj-geddes ios-swift-development — a skill for building native iOS apps in Swift. Includes MVVM architecture, SwiftUI for UI, URLSession networking, Combine for reactive flows, and Core Data persistence. CX Codex +1 1,500installs swift Mindrally Guides your agent to write clean Swift and SwiftUI code for iOS, macOS, watchOS, and tvOS using the MVVM pattern. CX Codex +1 748installs clerk-swift clerk clerk-swift — a Claude Code skill that builds Clerk authentication UI for native Swift apps on iOS and macOS. It configures prebuilt ClerkKitUI views or guides custom flows using ClerkKit. CX Codex +1 15,200installs swift-formatstyle dpearson2699 swift-formatstyle teaches AI assistants to replace legacy Formatter subclasses with Foundation FormatStyle in Swift and SwiftUI. Useful for locale-safe numbers, dates, and currencies. CX Codex +1 3,000installs swift-architecture-skill efremidze swift-architecture-skill is a Claude Code skill that guides architecture choices for SwiftUI and UIKit code. It activates for feature design, implementation, refactoring, and reviews. CX Codex +1 2,100installs swift-optimise pproenca The swift-optimise skill reviews Swift and SwiftUI performance across concurrency, rendering, and animation. Use it while profiling clinic modules. CX Codex +1 293installs

From the same set104

The whole set →
codeql-expert The codeql-expert skill guides CodeQL database setup, custom query writing, and vulnerability scans. Use it for SAST tasks, taint tracking, and GitHub security workflows. CX Codex +1 174installs skill-creator-expert skill-creator-expert guides you through designing, writing and checking PCL skills, from domain analysis to a frontmatter template and a quality checklist. CX Codex +1 173installs django-expert django-expert guides full-stack Django development covering ORM models, views, forms, authentication, and Django REST Framework APIs. CX Codex +1 172installs graphql-expert graphql-expert is a Claude Code skill for GraphQL schema design, resolvers, and subscriptions, with guidance on Apollo federation and N+1 queries. CX Codex +1 169installs data-mesh-expert data-mesh-expert walks the agent through data mesh work: domains own their data, products ship with contracts, governance is federated and the platform serves itself. CX Codex +1 168installs linkerd-expert linkerd-expert — a Linkerd skill for Kubernetes work: the agent installs the mesh, injects the proxy, pulls linkerd viz metrics and writes access policies. CX Codex +1 162installs pcl-expert pcl-expert — a skill for Persona Control Language: persona, team and workflow declarations, the compiler pipeline, the pcl toolchain. Useful when the agent edits .pcl files or the compiler itself. CX Codex +1 160installs sql-expert sql-expert — a skill for expert SQL work: schema design, efficient queries, index optimization, and administration across PostgreSQL, MySQL, and SQL Server. CX Codex +1 1installs

Project sponsors

Companies that keep this analytics open