swiftui-architecture

Guides SwiftUI view architecture using @State, @Binding, @Observable, and @Environment without ViewModels.

3|Updated Nov 8, 2014
One-click install
npx skills add https://github.com/mintuz/.dotfiles --skill swiftui-architecture-mintuz
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: swiftui-architecture
Source: https://github.com/mintuz/.dotfiles/tree/main/agents/.agents/skills/swiftui-architecture
Command: npx skills add https://github.com/mintuz/.dotfiles --skill swiftui-architecture-mintuz

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? SwiftUI developers often default to MVVM ViewModels, Combine pipelines, and misplaced state, producing tangled data flow and hard-to-test code. This Skill provides a consistent architecture for pure SwiftUI apps with clear ownership of state, services, and async work. ## Core Features & Use Cases - State Ownership Rules: Decide when a value stays in @State, lifts to a common ancestor via @Binding, or moves into a shared @Observable service injected through @Environment. - Async Lifecycle Patterns: Use .task and .task(id:) with explicit cancellation, debouncing, retry, and supersede policies for user-triggered work. - Navigation and UI Guides: Typed NavigationStack destinations, optional AppRouter integration, plus reference patterns for lists, grids, forms, sheets, tabs, and scroll views. - Use Case: When building a new SwiftUI screen that fetches data, presents sheets, and shares a user session across tabs, apply this Skill to structure state, services, and navigation without introducing a ViewModel layer. ## Quick Start Ask the AI to build a SwiftUI screen following the swiftui-architecture skill, for example a searchable item list with loading, error, and retry states.

Frequently Asked Questions about swiftui-architecture

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

FAQPage Schema
How do I manage state in SwiftUI without ViewModels?▼

Keep local UI state in @State within the view that uses it, lift shared values to the nearest common ancestor and pass them down as arguments or @Binding, and move domain state into @Observable services injected via @Environment only when it must outlive the view or is read by unrelated features.

How do I load async data in a SwiftUI view?▼

Use the .task modifier for work tied to the view's lifetime and .task(id:) for work that restarts when an input changes. Check Task.isCancelled before writing results to state, treat cancellation as a non-error, and hold user-triggered work in a Task stored in @State.

Should I use @StateObject with @Observable classes?▼

No. @StateObject is only for ObservableObject types. For classes marked with the @Observable macro, retain them once with @State and inject them into child views through the environment with .environment().

When should I use @Binding versus a callback in SwiftUI?▼

Use @Binding only when the child view genuinely needs to mutate the parent's state. When the child just reports events, pass callbacks like onAdd or onDelete so the parent controls how state changes, keeping intent explicit.

Does this SwiftUI architecture work with UIKit code?▼

The guidance does not restructure UIKit internals. Instead, wrap existing view controllers in UIViewControllerRepresentable, wrap standalone views in UIViewRepresentable, or embed SwiftUI in UIKit with UIHostingController, passing values in and events out through callbacks.

Why should I avoid Combine for simple async work in SwiftUI?▼

Combine publishers with @Published properties and cancellables add unnecessary machinery for one-shot async operations. Swift concurrency with async/await inside .task gives automatic cancellation when the view disappears and keeps error handling in one structured path.