swiftui-patterns

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

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill swiftui-patterns-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-patterns
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/swiftui-patterns
Command: npx skills add https://github.com/Femad-6/my-skills --skill swiftui-patterns-femad-6

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? SwiftUI developers often struggle with choosing the right property wrappers, structuring navigation, 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 destinations for programmatic routing. - 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 List with .task-based loading, and add type-safe navigation to detail views. ## Quick Start Ask the AI to build a SwiftUI list view with an @Observable view model and NavigationStack routing to a detail screen.

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 store 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, @Binding creates a two-way reference to a parent's @State, and @Observable classes hold shared 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 use navigationDestination(for:) to map each enum case to its destination view.

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 and simpler environment injection via @Environment.

Why is my SwiftUI List scrolling slowly?

Slow scrolling usually comes from eager containers, unstable ForEach identifiers, or expensive modifiers like shadows and blurs. Use LazyVStack, stable unique IDs, Equatable conformance on heavy views, and move async work out of body into .task.