Skip to content

Instantly share code, notes, and snippets.

@pietrorea
Created June 25, 2021 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pietrorea/8fc2c83a26322f3909ab630aee2f5414 to your computer and use it in GitHub Desktop.
Save pietrorea/8fc2c83a26322f3909ab630aee2f5414 to your computer and use it in GitHub Desktop.
Set initial view controller in code using SceneDelegate
// First, delete the two storyboard entries in the Info.plist (one newer one for SceneDelegate and a newer one for AppDelegate)
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else {
return
}
let blueViewController = UIViewController()
blueViewController.view.backgroundColor = .blue
let window = UIWindow(windowScene: windowScene)
window.rootViewController = blueViewController
self.window = window
window.makeKeyAndVisible()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment