swiftui-preview
SwiftUI Preview Architecture
Overview
When writing or refactoring SwiftUI code, you must strictly follow the Closure-Based Dependency Injection pattern. We do not use MVVM, nor do we use Protocol-based dependency injection (e.g., no ServiceProtocol, LiveService, MockService classes).
Instead, we use structs with @Sendable closures for services, @Observable classes for state management (Stores), and SwiftUI's native Environment for dependency injection.
Core Directives
1. No Protocols for Services
Never define a protocol for a service. Define a single struct marked Sendable where every operation is a @Sendable closure property.
Read references/01-closure-services.md for implementation details.
2. No View Models (Anti-MVVM)
Never create a ViewModel. The view's state is managed by an @Observable Store class owned by the Service. Views observe the store directly.
Read references/02-observable-stores.md for the Store and LoadingState implementation.