How to set initial storyboard

Viewed 10603

I have two storyboards one of them is default called Main and the other one I have just added is called Admin.

Main is used for customer, Admin is used for owner of the app.

I wonder how do you set initial/main interface storyboard programmatically.

enter image description here

P.S. I know how to change it via xcode but do not know programatically.

2 Answers

You can set your storyboard programmatically like this in the app delegate:

window = UIWindow(frame: UIScreen.main.bounds)
// Or "Admin"
window!.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateInitialViewController()! 
window!.makeKeyAndVisible()

You could actually set any view controller. That's how no-storyboard approach is wired up.

Oh, another advantage of doing it in code is it delays the storyboard initialization. If you use the "Main Interface" settings in Xcode, the storyboard is actually initialized BEFORE the application:didFinishLaunchingWithOptions method.

Related