Ok,
so this might be trivial, but I am not sure how to go about this.
I have a UIViewController that gets created when the SwiftUI view calls:
func makeUIViewController(context: Context) -> MyViewController
The View that makes that call was given an environment object in the SceneDelegate like we have seen in the tutorials:
window.rootViewController = UIHostingController(rootView: ContentView().environmentObject(MyData()))
What I am trying to do is to use that environment object (MyData()) within my UIViewController logic. The ViewController would read/write on MyData's instance as needed, and from what I understand that should cause the SwiftUI view to react accordingly since MyData conforms to BindableObject...
So in the makeUIViewController call I get the UIViewControllerRepresentableContext. I can see the environment in the context:
context.environment
and if I print it in the console during debug I see this:
context.environment: [EnvironmentPropertyKey<PreferenceBridgeKey> = Value(value: Optional(SwiftUI.PreferenceBridge)), EnvironmentPropertyKey<FontKey> = Optional(SwiftUI.Font(provider: SwiftUI.(unknown context at $1c652cbec).FontBox<SwiftUI.Font.(unknown context at $1c656e2cc).TextStyleProvider>)), .......
In the print I see the MyData environmentObject instance:
EnvironmentPropertyKey<StoreKey<MyData>> = Optional(MyApp.MyData), ...
I am not sure how to get MyData out of the environment values given to me in the context.environment....
I have tried to figure out how to get the proper EnvironmentKey for MyData so I could try access it view subscript ... context.environment[myKey...]
How can I get MyData back from the environment values given to me by the context?