I created an application in SwiftUI.
Views are structs, but I need to know the View Controller because it is needed for presenting some special alerts.
I see that in my project there are AppDelegate, and SceneDelegate.
I found this
let contentView = ContentView()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
window.makeKeyAndVisible()
}
So I want to pass the View Controller reference to the other Views.
Is window.rootViewController the right value to pass and use?
I do not know if this answer is a suitable solution, but it simply works for me, so be careful when using it.
the use the value like
from StackOverflow answer:
Get top most UIViewController