How to get navigation based template functionality in Swift programming

I would like to replicate your idea into what I usually do in the following example.

This is how my storyboard looks like:

enter image description here

As you can see login/signup and Tab bar is not connected with any kind of Segue.

Here Sign in Navigation controller is setup of Initial Controller.

Assign This Navigation Controller an Storyboard ID(e.g.LoginNavigation):

Login NavigationController

Do the same with Tab Bar Controller, assign Storyboard ID(e.g. HomeTabBar)

TabBarController

Now, you just have to shuffle Root View Controller of the app between Login Nav and Tab Bar.

So if user successfully logs in, changes the application’s root view to HomeTabBar using following code:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let home: UITabBarController = storyboard.instantiateViewControllerWithIdentifier("HomeTabBar") as! UITabBarController
appDelegate.window?.rootViewController = home

And when user logs our, again change the root view to Login Nav:

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let entryPoint:UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("LoginNavigation")
appDelegate.window?.rootViewController = entryPoint

The appDelegate is defined in my constants.swift file :

let appDelegate  = UIApplication.sharedApplication().delegate as! AppDelegate

Leave a Comment