title: Dismiss any loaded view in a navigation stack and return to the root of navigation stack
body: <p>Tab1 -&gt; Nav1 -&gt; Root1VC -&gt; Child1VC</p>
  <p>Tab2 -&gt; Nav2 -&gt; Root2VC -&gt; Child2VC</p>
  <p>In Root1VC I show different content based on user's login status.</p>
  <p>Lets's say I've visited Child1VC then tapped on Tab2, on Tab2 I tap on login. At this point I want to dismiss any presented views in Nav1 stack and return to root of Nav1 and call a func in Root1VC. How to do it?</p>
  <p>I've following code, which works but I'm not sure if this is the best approach.</p>
  <pre><code>let appDelegate = UIApplication.shared.delegate as! AppDelegate
  
  if let tabBar:UITabBarController = appDelegate.window?.rootViewController as? UITabBarController {
      
      if let menuNav:UINavigationController = tabBar.viewControllers?[2] as? UINavigationController {
          var topPresentedVC: UIViewController!
          
          if let topVC = menuNav.topViewController {
              topPresentedVC = topVC
              
          } else if let presentedVC = menuNav.presentedViewController {
              topPresentedVC = presentedVC
          }
          
          if topPresentedVC != nil {
              if !topPresentedVC.isKind(of: MoreViewController.classForCoder()) {
                  topPresentedVC.navigationController?.popToRootViewController(animated: false)
              }
              
              if let moreVC = menuNav.viewControllers.first as? MoreViewController {
                  moreVC.initMenus()
              } else {
                  print(&quot;Can't find first VC&quot;)
              }
          }
      }
  }
  </code></pre>