swiftui-architecturelisted
Install: claude install-skill hmj1026/dhpk
# SwiftUI architecture — MVVM + Coordinator
Load references on demand:
- `references/mvvm-coordinator.md` — layer responsibilities, DI/factory, Coordinator protocol.
- `references/observation-state.md` — `@Observable`/`@Bindable` vs `ObservableObject`, ownership.
- `references/navigation.md` — `NavigationStack`/`NavigationPath`, type-safe routes.
- `references/interop.md` — Combine bridge + `UIViewRepresentable`/`UIHostingController`.
---
## Core rules
1. **Views are thin and declarative.** No business logic, no persistence, no
networking in a `View`. A view reads state from its view model and sends
intents back. Logic that isn't "how to render" belongs in the view model or a
service.
2. **View models are `@Observable @MainActor`.** On the iOS 17 floor prefer the
Observation framework (`@Observable`) over `ObservableObject` + `@Published`.
Don't mix the two paradigms in one type. Inject dependencies (services) via
the initializer behind protocols — never `import`-reach into singletons.
3. **Navigation is owned by a Coordinator, not scattered in views.** A
`NavigationStack` bound to a coordinator-held `NavigationPath`; views append
typed route values, the coordinator maps routes → destination views.
4. **State ownership is explicit.** `@State` for value-typed view-local state;
`@Bindable` for a two-way binding to an `@Observable` model; `@Binding` for
delegated ownership; `@Environment` for ambient dependencies. Owning the same
state in