Skip to content

Instantly share code, notes, and snippets.

@Toni77777
Last active October 21, 2023 18:35
Show Gist options
  • Save Toni77777/d38e3aa5f5cd4d0b7c2ae892ab161840 to your computer and use it in GitHub Desktop.
Save Toni77777/d38e3aa5f5cd4d0b7c2ae892ab161840 to your computer and use it in GitHub Desktop.
Set rootViewController in SceneDelegate (Since iOS 13 and Xcode 11)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
// Get UIWindowScene
guard let windowScene = (scene as? UIWindowScene) else {
return
}
// Create a new window property
self.window = UIWindow(frame: windowScene.coordinateSpace.bounds)
// Set windowScene for window
self.window?.windowScene = windowScene
// Set custom LoginViewController as root
window?.rootViewController = LoginViewController()
// Present the window
window?.makeKeyAndVisible()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment