class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.rootViewController = HomeViewController() // rootView로 변경하고자 하는 ViewController
window?.makeKeyAndVisible()
}
}
rootView의 변경을 시도하는 곳이 UIView를 상속한 class라면 해당 view의 window 속성을 통해 rootView를 변경할 수 있습니다.
self.view.window?.rootViewController = HomeViewController()
UIApplication.shared.windows.first?.rootViewController = HomeViewController()
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let window = windowScene.windows.first(where: { $0.isKeyWindow }) {
window.rootViewController = HomeViewController()
}