2

将 UIWindow.rootView 转换为托管控制器,例如:

window?.rootViewController as? UIHostingController<MainTabView>

工作正常,除非它有environmentObjects.

由于 myMainTabView已被初始化.environmentObject,因此我无法将其强制转换为UIHostingController<MainTabView>.

当我尝试 printrootView的类型时,Xcode 告诉:

<_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentGS1_V10Panparella11MainTabViewGVS_30_EnvironmentKeyWritingModifierGSqCS2_11GroupsStore___GS4_GSqCS2_18GroupsPresentation____: 0x7fd8afe5da40>

我想是:

UIHostingController<ModifiedContent<MainTabView, _EnvironmentKeyWritingModifier<GroupsStore, GroupsPresentation>>>

但我无法到达_EnvironmentKeyWritingModifier

有人有想法吗?

4

0 回答 0