i have a UIHostingController that is hosting a SwiftUI view called CatalogView. when showing it, an environment object is attached, so basically from UIKit it is shown like this:
let rootCatalogView = CatalogView()
let appState = AppState.get()
let catalogView = UIHostingController(rootView: rootCatalogView.environmentObject(appState))
navigationController.pushViewController(catalogView, animated: true)
now at a later time i need to check if this UIHostingController is in the list of navigationController.viewControllers
the type(of:) is showing the following, which kind of make sense:
UIHostingController<ModifiedContent<CatalogView, _EnvironmentKeyWritingModifier<Optional<AppState>>>>
things like vc.self is UIHostingController.Type or vc.self is UIHostingController< CatalogView >.Type both return false (vc is an element of navigationController.viewControllers
the following obviously works, it returns true, but any change in the initialisation of the UIHostingController will change its type
vc.isKind(of: UIHostingController<ModifiedContent<CatalogView, _EnvironmentKeyWritingModifier<Optional<StoreManager>>>>.self)
how can i check if the view controller is of type UIHostingController? or at least how can i cast the controller to UIHostingController so that i can check its rootview?
catalogView
a property and then check something likeif navigationController.viewControllers.contains(catalogView) { ... }
? (typed in browser, not tested in Xcode). – Faunia