Setting Login Controller to Root ViewController in Swift

I’m trying to add Digits Login to my Tab Bar app. Currently, TabBarController is set to RootViewController in the hierarchy. In the appdelegate, the code for the tabBar Controller is as follows:

and the LoginViewController is as follows:

Any advice on code I should add, delete or some secret function only known to expert Jedi coders?

So, if I’ve read this right: you’ve created a subclass UITabBarController, called LoginViewController. When this view controller loads, it creates an DGTAuthenticateButton to… check if the user’s already logged in, I’m guessing?

If a session exists (which I assume means the user is logged in), viewDidLoad then does something very strange. It segues to another view controller (via the segue called loginSegue) and it presents a UIAlertController to tell the user they’re already logged in - it’s presenting two view controllers to the user at the same time. (The alert view also does something strange in telling the user they’re logged in with the option of cancelling the log in. Is ‘Cancel’ the right word there?)
If a session doesn’t exist (does this mean the user is not logged in?) the console prints an error message.

I can’t tell you what to add or delete - you haven’t explained what behaviour you intended to happen, and how this differs from your expectation. Should the segue only occur if the user is not logged in?

I’m referring to iOS Apprentice’s ‘MyLocations’. I asked the question under that forum category but everyone’s at the conference in SF so I probably won’t get a response until next week. I spoke to a local swift developer and he suggested I create an NSArray. I checked stackoverflow and I’m still unsure of how to construct. The error I keep getting lies in the appDelegate Bool:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) → Bool {


let tabBarController = window!.rootViewController as! UITabBarController

if let tabBarViewControllers = tabBarController.viewControllers {
  let currentLocationViewController = tabBarViewControllers[0] as! CurrentLocationViewController
  currentLocationViewController.managedObjectContext = managedObjectContext
  let navigationController = tabBarViewControllers[1] as! UINavigationController
  let locationsViewController = navigationController.viewControllers[0] as! LocationsViewController
  locationsViewController.managedObjectContext = managedObjectContext

  let mapViewController = tabBarViewControllers[2] as! MapViewController
  mapViewController.managedObjectContext = managedObjectContext
  // Workaround for the Core Data bug.
  let _ = locationsViewController.view

return true


If I attach any viewController (UI, TabBar) and set it to ‘initial View Controller’, it crashes when the self. perform segue is activated (for UIViewController) or crashes when I select a TabBar item that contains a Navigation Controller (UITabBarController).

So, from the AppDelegate code I provided, do you have any suggestions on how to make the initial view controller not crash? Your reply is greatly appreciated.

I’m completely lost.