In my appdelegate I want to check if globUs.hasName
. If it does I want the Entry Point
of the app to be my main
storyboard. If it does not I want the Entry Point
of the app to be my newUser
storyboard. How do I set the entry point of the app? If I can't, what is the most effective way to implement this functionality?
Asked
Active
Viewed 4,804 times
6

Gabe Spound
- 146
- 2
- 14
-
just set the self.window?.rootViewController as your preferred viewController in didFinishLaunchingWithOptions function. – Maryam Fekri Feb 11 '17 at 06:46
2 Answers
5
Consider not having an entry point. Then, in appDelegate, test for your variable and choose the appropriate storyboard accordingly. Then show the view controller from that storyboard.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if globUs.hasName {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "FirstMainVC")
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = new
self.window?.makeKeyAndVisible()
}
else {
let storyboard = UIStoryboard(name: "NewUser", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "FirstNewUserVC")
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = welcomeVC
self.window?.makeKeyAndVisible()
}
return true
}

Shades
- 5,568
- 7
- 30
- 48
-
When I use a method similar to this AppDel throws a SIGABRT. It says that "'Could not find a storyboard named 'OneStoryboard' in bundle NSBundle (loaded)'" What does the "name:" field mean in the UIStoryboard constructor? Is it arbitrary or do I have to use the filename of my Main.storyboard? – Gabe Spound Feb 15 '17 at 20:56
-
0
Try
var sb = UIStoryboard(name: "OneStoryboard", bundle: nil)
/// Load initial view controller
var vc = sb.instantiateInitialViewController()
/// Or load with identifier
var vc = instantiateViewController(withIdentifier: "foobarViewController")
/// Set root window and make key and visible
self.window = UIWindow(frame: UIScreen.mainScreen.bounds)
self.window.rootViewController = vc
self.window.makeKeyAndVisible()
Or try manual segue in storyboard. To perform manual segue, you have to first define a segue with identifier in storyboard and then call performSegue(withIdentifier:sender:)
in view controller.

legendecas
- 359
- 2
- 8
-
Check the comment I left for the answer above, it pertains here as well. – Gabe Spound Feb 15 '17 at 20:57
-
1