04
Product
16
Backend
09
Auth
12
iOS
07
Infra
02
Real-Time

Use SwiftUI previews with mock services

ADR-0050 ACCEPTED · 2026-03-01
SwiftUI preview strategy with mock services

Context

The MV + Environment Services architecture (ADR-0003) means views trigger fetches on onAppear and observe service properties. This is correct for the running app but breaks Xcode Previews — previews can't make real network calls, and async work causes hangs or crashes.

Decision

Mock services that short-circuit async paths. Services provide a mock() factory method that returns immediately with pre-populated data and no network calls.

Use Apple's PreviewModifier pattern to create shared mock service context once, injected via .environment(). Named preview traits (WithTripPreview, LoggedOutPreview, LoadingTripPreview, ErrorTripPreview, ViewerRolePreview) cover the common states.

Don't restructure views to accept data as parameters just to make previews easier — that fights the architecture. Fix the mocks instead.

Consequences

Previews render instantly with realistic data. Adding a new preview state is one PreviewModifier conformance. The trade-off is maintaining mock factories alongside real services — when a service gains a new property, the mock needs updating too.