swiftui-architecture

Advises on SwiftUI architecture patterns, state management, view composition, navigation, and testing.

5|Updated Sep 24, 2017
One-click install
npx skills add https://github.com/madyankin/dotfiles --skill swiftui-architecture-madyankin
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: swiftui-architecture
Source: https://github.com/madyankin/dotfiles/tree/main/.config/agents/skills/swiftui-architecture
Command: npx skills add https://github.com/madyankin/dotfiles --skill swiftui-architecture-madyankin

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? SwiftUI developers often struggle with choosing the right architecture pattern, managing state correctly across view hierarchies, and avoiding performance pitfalls like unstable view identity and unnecessary re-renders. This Skill provides expert guidance grounded in Apple's own recommendations to build maintainable, performant SwiftUI applications. ## Core Features & Use Cases - Architecture Pattern Guidance: Compares MV, MVVM, Clean Architecture, and modular approaches with concrete Swift code examples and decision criteria for app size and team structure. - State Management Reference: Explains when to use @State, @Binding, @StateObject, @ObservedObject, @EnvironmentObject, and the modern @Observable macro, with a source-of-truth hierarchy model. - Performance & Identity Best Practices: Covers stable identifiers in ForEach, inert modifiers, dependency scope minimization, and common anti-patterns to avoid. - Use Case: When building a client/server iOS app, ask how to structure stores and views; the Skill recommends a single @Observable store per bounded context with container/presenter view separation, plus testable form structs and protocol-based network mocking. ## Quick Start Ask how to structure state management and navigation for a new SwiftUI app with multiple screens and a shared data store.

Frequently Asked Questions about swiftui-architecture

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

FAQPage Schema
Should I use MVVM or MV pattern in SwiftUI?▼

Apple's own samples use the MV pattern where views act as their own view model backed by @Observable stores. Traditional MVVM with one ViewModel per view often creates competing sources of truth and boilerplate. Use MVVM only when a view has complex independently testable logic or needs isolation from SwiftUI.

When should I use @State vs @StateObject vs @Observable in SwiftUI?▼

Use @State for local transient UI state, @StateObject when a view owns an ObservableObject lifecycle, and @Observable (iOS 17+) as the modern replacement for ObservableObject. Use @Binding to let children mutate parent state and @Environment for values needed deep in the hierarchy.

Why does my SwiftUI view state reset unexpectedly?▼

State resets when view identity changes, because @State storage is tied to identity rather than value. Common causes include using random UUIDs in ForEach, array indices as IDs, or if/else branches that create separate view identities instead of inert modifiers like opacity.

How do I test SwiftUI view logic and network code?▼

Extract form validation and business logic into plain structs that can be unit tested without SwiftUI dependencies. Hide the HTTP client behind a protocol so stores can be tested with stub implementations, and use Xcode Previews with sample data for fast visual feedback.

Does SwiftUI NavigationStack support programmatic navigation?▼

Yes, NavigationStack (iOS 16+) supports programmatic navigation through a NavigationPath stored in an @Observable router. You append typed route enums to push destinations and remove path elements to pop back, enabling deep linking and centralized navigation control.