All skills
johnrogers avatar

/swiftui-advanced

@d62eb71

Use when implementing gesture composition (simultaneous, sequenced, exclusive), adaptive layouts (ViewThatFits, AnyLayout, size classes), or choosing architecture patterns (MVVM vs TCA vs vanilla, State-as-Bridge). Covers advanced SwiftUI patterns beyond basic views.

Use this Skill: https://skilld.dev/gh/johnrogers/claude-swift-engineering/swiftui-advanced

This session only. Nothing lands on disk.

referencesarchitecture.md

≈671 tokens on demand. Your agent reads this file only when SKILL.md points to it.

SwiftUI Architecture

Architecture Decision Tree

- Small/medium app, Apple's patterns? -> @Observable + State-as-Bridge
- Familiar with MVVM from UIKit? -> MVVM with @Observable ViewModels
- Rigorous testability, large team? -> TCA (Composable Architecture)
- Complex navigation, deep linking? -> Add Coordinator Pattern

Property Wrapper Decision

- View owns the model? -> @State
- App-wide model? -> @Environment
- Need bindings to parent's model? -> @Bindable
- Just reading? -> Plain property (no wrapper)

State-as-Bridge Pattern (WWDC 2025)

Async creates suspension points that break animations:

// WRONG
Task { isLoading = true; await work(); isLoading = false }

// CORRECT - synchronous state changes for animation
withAnimation { isLoading = true }
Task {
    await work()
    withAnimation { isLoading = false }
}

MVVM Structure

// Model - domain logic
struct Pet: Identifiable {
    let id: UUID; var name: String
    mutating func giveAward() { hasAward = true }
}

// ViewModel - presentation logic
@Observable
class PetListViewModel {
    private let petStore: PetStore
    var searchText = ""

    var filteredPets: [Pet] {
        petStore.myPets.filter { searchText.isEmpty || $0.name.contains(searchText) }
    }
}

// View - UI only
struct PetListView: View {
    @Bindable var viewModel: PetListViewModel

    var body: some View {
        List(viewModel.filteredPets) { PetRow(pet: $0) }
            .searchable(text: $viewModel.searchText)
    }
}

TCA Trade-offs

Scenario Choice
< 10 screens Apple patterns
Testability critical TCA
Large team TCA for consistency
Rapid prototyping Apple patterns

Anti-Patterns

Logic in view body:

// WRONG - formatter created every render
var body: some View {
    let formatter = NumberFormatter()
    Text(formatter.string(from: price)!)
}

// CORRECT - cache in model
class ViewModel {
    private let formatter = NumberFormatter()
    func format(_ price: Decimal) -> String { ... }
}

Wrong property wrapper:

// WRONG - @State copies, loses parent changes
struct DetailView: View { @State var item: Item }

// CORRECT
struct DetailView: View { let item: Item }  // or @Bindable

God ViewModel:

// WRONG
class AppViewModel { var user; var settings; var posts; ... }

// CORRECT - separate concerns
class UserViewModel { }
class SettingsViewModel { }

Code Review Checklist

  • View bodies contain ONLY UI code
  • No formatters in view body
  • Business logic testable without SwiftUI
  • State changes for animations are synchronous

Source: SKILL.md on GitHub

1 warning16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill is a collection of reference documentation and code patterns for advanced SwiftUI development. No security issues, malicious code, or suspicious instructions were detected.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    5/5 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at d62eb71. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Dormantupdated 9 months ago

README badge

README badge for johnrogers/claude-swift-engineering/swiftui-advanced