swiftui-patterns

Implements SwiftUI state management, navigation, and performance patterns for iOS and macOS apps.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill swiftui-patterns-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-patterns
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/swiftui-patterns
Command: npx skills add https://github.com/ibytechaos/claude --skill swiftui-patterns-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? SwiftUI developers often struggle with choosing the right property wrappers, structuring view models, and avoiding unnecessary view re-renders, leading to buggy state handling and sluggish interfaces. ## Core Features & Use Cases - Modern State Management: Guides selection between @State, @Binding, @Observable, @Bindable, and @Environment, replacing legacy ObservableObject patterns. - Type-Safe Navigation: Implements NavigationStack with NavigationPath and enum-based routing for programmatic navigation flows. - Performance Optimization: Covers lazy containers, stable identifiers, Equatable conformance, and avoiding expensive work in view bodies. - Use Case: When building an item list screen, use this Skill to structure an @Observable view model, wire it to a view with .task-based loading, and render large collections efficiently with LazyVStack. ## Quick Start Ask the AI to refactor a SwiftUI view to use @Observable state management with type-safe NavigationStack routing.

Frequently Asked Questions about swiftui-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I manage state in SwiftUI with @Observable?

Define an @Observable final class as your view model and hold it in the view with @State. SwiftUI tracks property-level changes, so only views reading a changed property re-render, replacing the older ObservableObject and @Published approach.

What is the difference between @State, @Binding, and @Observable in SwiftUI?

@State holds view-local value types like toggles, @Binding creates a two-way reference to a parent's @State, and @Observable classes manage models with multiple properties. Use @Bindable when you need two-way binding to an @Observable property.

How do I implement type-safe navigation with NavigationStack?

Create a Router class holding a NavigationPath and define a Hashable enum for destinations. Bind the path to NavigationStack and map destinations with .navigationDestination, enabling programmatic push and popToRoot navigation.

Should I still use ObservableObject and @StateObject in new SwiftUI code?

No, new code should use the @Observable macro instead of ObservableObject, @Published, @StateObject, and @EnvironmentObject. The Observation framework provides finer-grained change tracking so only affected views re-render.

Why is my SwiftUI List scrolling slowly?

Slow scrolling usually comes from eager rendering, unstable identifiers, or expensive modifiers. Use LazyVStack inside ScrollView, provide stable unique IDs in ForEach, and minimize .shadow(), .blur(), and .mask() in list rows.

When should I avoid putting async work in a SwiftUI view body?

Never perform I/O, network calls, or heavy computation inside body, since it runs on every re-render. Use .task {} for async work, which starts when the view appears and cancels automatically when it disappears.