swiftui-patterns — ai-agents swiftui-patterns, everything-claude-code, official, ai-agents, ide skills, anthropic, claude-code, developer-tools, Claude Code, Cursor, Windsurf

Verified
v1.0.0
GitHub

About this Skill

Perfect for iOS/macOS Development Agents needing advanced SwiftUI architecture patterns and performance optimization techniques. SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

# Core Topics

affaan-m affaan-m
[60.6k]
[7501]
Updated: 3/5/2026

Agent Capability Analysis

The swiftui-patterns skill by affaan-m is an open-source official AI agent skill for Claude Code and other IDE workflows, helping agents execute tasks with better context, repeatability, and domain-specific guidance. Optimized for ai-agents, anthropic, claude-code.

Ideal Agent Persona

Perfect for iOS/macOS Development Agents needing advanced SwiftUI architecture patterns and performance optimization techniques.

Core Value

Empowers agents to build declarative, performant user interfaces using SwiftUI, leveraging the Observation framework, view composition, type-safe navigation, and performance optimization with @Observable, @State, and @Binding. It provides best practices for structuring view models, data flow, and optimizing rendering performance for lists and complex layouts.

Capabilities Granted for swiftui-patterns

Building scalable SwiftUI views with @State and @Observable
Designing efficient navigation flows with NavigationStack
Optimizing rendering performance for complex layouts and lists
Structuring view models and data flow for modern iOS/macOS UI

! Prerequisites & Limits

  • Requires knowledge of Swift programming language
  • Apple platforms only (iOS, macOS)
Labs Demo

Browser Sandbox Environment

⚡️ Ready to unleash?

Experience this Agent in a zero-setup browser environment powered by WebContainers. No installation required.

Boot Container Sandbox

swiftui-patterns

Install swiftui-patterns, an AI agent skill for AI agent workflows and automation. Works with Claude Code, Cursor, and Windsurf with one-command setup.

SKILL.md
Readonly

SwiftUI Patterns

Modern SwiftUI patterns for building declarative, performant user interfaces on Apple platforms. Covers the Observation framework, view composition, type-safe navigation, and performance optimization.

When to Activate

  • Building SwiftUI views and managing state (@State, @Observable, @Binding)
  • Designing navigation flows with NavigationStack
  • Structuring view models and data flow
  • Optimizing rendering performance for lists and complex layouts
  • Working with environment values and dependency injection in SwiftUI

State Management

Property Wrapper Selection

Choose the simplest wrapper that fits:

WrapperUse Case
@StateView-local value types (toggles, form fields, sheet presentation)
@BindingTwo-way reference to parent's @State
@Observable class + @StateOwned model with multiple properties
@Observable class (no wrapper)Read-only reference passed from parent
@BindableTwo-way binding to an @Observable property
@EnvironmentShared dependencies injected via .environment()

@Observable ViewModel

Use @Observable (not ObservableObject) — it tracks property-level changes so SwiftUI only re-renders views that read the changed property:

swift
1@Observable 2final class ItemListViewModel { 3 private(set) var items: [Item] = [] 4 private(set) var isLoading = false 5 var searchText = "" 6 7 private let repository: any ItemRepository 8 9 init(repository: any ItemRepository = DefaultItemRepository()) { 10 self.repository = repository 11 } 12 13 func load() async { 14 isLoading = true 15 defer { isLoading = false } 16 items = (try? await repository.fetchAll()) ?? [] 17 } 18}

View Consuming the ViewModel

swift
1struct ItemListView: View { 2 @State private var viewModel: ItemListViewModel 3 4 init(viewModel: ItemListViewModel = ItemListViewModel()) { 5 _viewModel = State(initialValue: viewModel) 6 } 7 8 var body: some View { 9 List(viewModel.items) { item in 10 ItemRow(item: item) 11 } 12 .searchable(text: $viewModel.searchText) 13 .overlay { if viewModel.isLoading { ProgressView() } } 14 .task { await viewModel.load() } 15 } 16}

Environment Injection

Replace @EnvironmentObject with @Environment:

swift
1// Inject 2ContentView() 3 .environment(authManager) 4 5// Consume 6struct ProfileView: View { 7 @Environment(AuthManager.self) private var auth 8 9 var body: some View { 10 Text(auth.currentUser?.name ?? "Guest") 11 } 12}

View Composition

Extract Subviews to Limit Invalidation

Break views into small, focused structs. When state changes, only the subview reading that state re-renders:

swift
1struct OrderView: View { 2 @State private var viewModel = OrderViewModel() 3 4 var body: some View { 5 VStack { 6 OrderHeader(title: viewModel.title) 7 OrderItemList(items: viewModel.items) 8 OrderTotal(total: viewModel.total) 9 } 10 } 11}

ViewModifier for Reusable Styling

swift
1struct CardModifier: ViewModifier { 2 func body(content: Content) -> some View { 3 content 4 .padding() 5 .background(.regularMaterial) 6 .clipShape(RoundedRectangle(cornerRadius: 12)) 7 } 8} 9 10extension View { 11 func cardStyle() -> some View { 12 modifier(CardModifier()) 13 } 14}

Type-Safe NavigationStack

Use NavigationStack with NavigationPath for programmatic, type-safe routing:

swift
1@Observable 2final class Router { 3 var path = NavigationPath() 4 5 func navigate(to destination: Destination) { 6 path.append(destination) 7 } 8 9 func popToRoot() { 10 path = NavigationPath() 11 } 12} 13 14enum Destination: Hashable { 15 case detail(Item.ID) 16 case settings 17 case profile(User.ID) 18} 19 20struct RootView: View { 21 @State private var router = Router() 22 23 var body: some View { 24 NavigationStack(path: $router.path) { 25 HomeView() 26 .navigationDestination(for: Destination.self) { dest in 27 switch dest { 28 case .detail(let id): ItemDetailView(itemID: id) 29 case .settings: SettingsView() 30 case .profile(let id): ProfileView(userID: id) 31 } 32 } 33 } 34 .environment(router) 35 } 36}

Performance

Use Lazy Containers for Large Collections

LazyVStack and LazyHStack create views only when visible:

swift
1ScrollView { 2 LazyVStack(spacing: 8) { 3 ForEach(items) { item in 4 ItemRow(item: item) 5 } 6 } 7}

Stable Identifiers

Always use stable, unique IDs in ForEach — avoid using array indices:

swift
1// Use Identifiable conformance or explicit id 2ForEach(items, id: \.stableID) { item in 3 ItemRow(item: item) 4}

Avoid Expensive Work in body

  • Never perform I/O, network calls, or heavy computation inside body
  • Use .task {} for async work — it cancels automatically when the view disappears
  • Use .sensoryFeedback() and .geometryGroup() sparingly in scroll views
  • Minimize .shadow(), .blur(), and .mask() in lists — they trigger offscreen rendering

Equatable Conformance

For views with expensive bodies, conform to Equatable to skip unnecessary re-renders:

swift
1struct ExpensiveChartView: View, Equatable { 2 let dataPoints: [DataPoint] // DataPoint must conform to Equatable 3 4 static func == (lhs: Self, rhs: Self) -> Bool { 5 lhs.dataPoints == rhs.dataPoints 6 } 7 8 var body: some View { 9 // Complex chart rendering 10 } 11}

Previews

Use #Preview macro with inline mock data for fast iteration:

swift
1#Preview("Empty state") { 2 ItemListView(viewModel: ItemListViewModel(repository: EmptyMockRepository())) 3} 4 5#Preview("Loaded") { 6 ItemListView(viewModel: ItemListViewModel(repository: PopulatedMockRepository())) 7}

Anti-Patterns to Avoid

  • Using ObservableObject / @Published / @StateObject / @EnvironmentObject in new code — migrate to @Observable
  • Putting async work directly in body or init — use .task {} or explicit load methods
  • Creating view models as @State inside child views that don't own the data — pass from parent instead
  • Using AnyView type erasure — prefer @ViewBuilder or Group for conditional views
  • Ignoring Sendable requirements when passing data to/from actors

References

See skill: swift-actor-persistence for actor-based persistence patterns. See skill: swift-protocol-di-testing for protocol-based DI and testing with Swift Testing.

FAQ & Installation Steps

These questions and steps mirror the structured data on this page for better search understanding.

? Frequently Asked Questions

What is swiftui-patterns?

Perfect for iOS/macOS Development Agents needing advanced SwiftUI architecture patterns and performance optimization techniques. SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

How do I install swiftui-patterns?

Run the command: npx killer-skills add affaan-m/everything-claude-code/swiftui-patterns. It works with Cursor, Windsurf, VS Code, Claude Code, and 19+ other IDEs.

What are the use cases for swiftui-patterns?

Key use cases include: Building scalable SwiftUI views with @State and @Observable, Designing efficient navigation flows with NavigationStack, Optimizing rendering performance for complex layouts and lists, Structuring view models and data flow for modern iOS/macOS UI.

Which IDEs are compatible with swiftui-patterns?

This skill is compatible with Cursor, Windsurf, VS Code, Trae, Claude Code, OpenClaw, Aider, Codex, OpenCode, Goose, Cline, Roo Code, Kiro, Augment Code, Continue, GitHub Copilot, Sourcegraph Cody, and Amazon Q Developer. Use the Killer-Skills CLI for universal one-command installation.

Are there any limitations for swiftui-patterns?

Requires knowledge of Swift programming language. Apple platforms only (iOS, macOS).

How To Install

  1. 1. Open your terminal

    Open the terminal or command line in your project directory.

  2. 2. Run the install command

    Run: npx killer-skills add affaan-m/everything-claude-code/swiftui-patterns. The CLI will automatically detect your IDE or AI agent and configure the skill.

  3. 3. Start using the skill

    The skill is now active. Your AI agent can use swiftui-patterns immediately in the current project.

Related Skills

Looking for an alternative to swiftui-patterns or another official skill for your workflow? Explore these related open-source skills.

View All

flags

Logo of facebook
facebook

Use when you need to check feature flag states, compare channels, or debug why a feature behaves differently across release channels.

243.6k
0
Developer

extract-errors

Logo of facebook
facebook

Use when adding new error messages to React, or seeing unknown error code warnings.

243.6k
0
Developer

fix

Logo of facebook
facebook

Use when you have lint errors, formatting issues, or before committing code to ensure it passes CI.

243.6k
0
Developer

flow

Logo of facebook
facebook

Use when you need to run Flow type checking, or when seeing Flow type errors in React code.

243.6k
0
Developer