Questions » Recent Q&A » How to access the rootViewController

How to access the rootViewController

Posted 5 days ago
  • I found a solution here (objective-c):

    (see there: Instantiating The Application User Interface)

    ...and implemented this in my AppDelegate in Swift:

    Member variable:

        var run_once: Bool = false

    modified didAuthorize:

    func didAuthorize() -> Void {

        print(#file, #function)
        //I added this if block:
        if !self.run_once {
            self.run_once = true
            let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HomeController") as? HomeController
            window = UIWindow()
            window?.rootViewController = controller
  !.rootViewController = controller

    Now the app runs fine in release mode too (only tested with Simulator!).

  • Glad to hear you have it working now.  Thank you for following up with the solution!