For a new SwiftUI iOS app, I do the following in the SceneDelegate
if let windowScene = scene as? UIWindowScene {
let window =
You can make a Router class
import Foundation
import UIKit
import SwiftUI
class Router {
class var window: UIWindow? {
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
if let sceneDelegate = scene.delegate as? SceneDelegate {
let window = UIWindow(windowScene: scene)
sceneDelegate.window = window
window.makeKeyAndVisible()
return window
}
}
return nil
}
static func showMain() {
window?.rootViewController = UIHostingController(rootView: ContentView())
}
}
Usage :
Router.showMain()
And with this you can decide which window you want as your root at any given time.