For a new SwiftUI
iOS app, I do the following in the SceneDelegate
if let windowScene = scene as? UIWindowScene {
let window =
let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene
if let windowScenedelegate = scene?.delegate as? SceneDelegate {
let window = UIWindow(windowScene: scene!)
window.rootViewController = UIHostingController(rootView:ContentView())
windowScenedelegate.window = window
window.makeKeyAndVisible()
}
By using this we can change the rootView in any button click by implementing the above code.