title: Change root View Controller
body: <p>I have a problem with changing root in my app.</p>
  
  <p><a href="https://i.stack.imgur.com/NtGUJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NtGUJ.png" alt="enter image description here"></a></p>
  
  <p>Design of my app.
  After I login into app I would like to change root vc to <code>UITabBarViewController</code> to clean a stack.</p>
  
  <p>I've faced multiple problems.</p>
  
  <ol>
  <li><p>Setting vc to tab bar on apply login action -> or in bottom vc:</p>
  
  <pre><code>self.performSegue(withIdentifier: "goToMainTabBar", sender: nil)
  
  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if let vc = segue.destination as? TabBarViewController {
          UIApplication.shared.keyWindow?.rootViewController = vc
      }
  }
  </code></pre></li>
  </ol>
  
  <p>The app going to crash with: </p>
  
  <pre><code>Application tried to present modal view controller on itself. Presenting controller is TabBarViewController
  </code></pre>
  
  <ol start="2">
  <li><p>Next problem is if we set a root in <code>TabBarViewController</code> <code>viewDidLoaded</code>.</p>
  
  <p><code>UIApplication.shared.keyWindow?.rootViewController = self</code></p></li>
  </ol>
  
  <p>Tab bar items embaded in <code>UINavigationController</code> doesnt have Navigation controller in it selfs, so the nav vc is not instantiated ? Becouse wheenver I will enter into item vc child -> I can't back any more. 
  If i won;t change a root vc there everything is fine.</p>