UPDATE: Ended up creating a wrapper view MyView_RUNTIME which has the runtime dependencies specified.
This way in the #preview block you can instantiate MyView with your dummy environment variables, while in the UIHostingController you can instantiate the real ones.
ie:
// use within UIHostingController (ie: super.init( coder: aDecoder, rootView: DebugView_RUNTIME() ))
struct MyView_RUNTIME : View {
var body: some View {
MyView().environment( \.database, ServiceLocator.database ) // NOTE: real DB registered during the bootstrapping of the runtime app
}
}
// use within previews
#Preview {
MyView().environment( \.database, MyDatabase( inMemory: true )) // in-memory, dummy database
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: