I am new to SwiftUI and facing a problem where I want to change the root view when a certain action occurs inside the app.
How I handle it when using SceneDelegate
was as follows
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
... // the code of initializing the window
observeOnChangeWindow()
}
func observeOnChangeWindow(){
NotificationCenter.default.addObserver(self, selector: #selector(self.performChangeWindow), name: Notification.Name(K.changeWindowNotificationName), object: nil)
}
@objc func performChangeWindow() {
self.window?.rootViewController = UIHostingController(rootView: SplashScreenView())
}
However, I am not currently using SceneDelegate as I am initializing the app using WindowGroup
struct MyApp: App {
var body: some Scene {
WindowGroup {
SplashScreenView()
}
}
}
My question is : How can I perform the same thing I am doing using SceneDelegate now ?