Post

Replies

Boosts

Views

Activity

Reply to How to create UIHostingController and pass environmentObject?
How do you get this working with previews though? Presumable with previews you may want to pass in dummy environment objects/services: MyView().environment( \.database, database ) whereas in the runnable app you might want the hosting controller to pass along other services. Specifying it in the view definition itself doesn't allow you to pass it in from the outside.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Oct ’23
Reply to How to create UIHostingController and pass environmentObject?
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:
Oct ’23
Reply to Advanced app clip experiences with multiple domains
Did you get any resolution on this? In the same boat here and wondering what the best-practice / solution you ended up going with.
Topic: App & System Services SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jul ’22
Reply to Unexpected(?) behaviour when loading an extension's internal URL
This still seems to be happening as of iOS 16.1. What's the status of the radar bug tracking this issue?
Topic: Safari & Web SubTopic: General Tags:
Replies
Boosts
Views
Activity
Nov ’22
Reply to How to create UIHostingController and pass environmentObject?
How do you get this working with previews though? Presumable with previews you may want to pass in dummy environment objects/services: MyView().environment( \.database, database ) whereas in the runnable app you might want the hosting controller to pass along other services. Specifying it in the view definition itself doesn't allow you to pass it in from the outside.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Oct ’23
Reply to How to create UIHostingController and pass environmentObject?
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:
Replies
Boosts
Views
Activity
Oct ’23