title: Present a view controller, dismiss it and present a different one in Swift
body: <p>I have a root view controller that has a button that when the user pushes it, another view controller is presented.</p>
  <p>This second controller has a dismiss option that just comes back to the root view controller and a button that when the user touches it dismisses the current view controller so it goes back to the root view controller for a second and presents another one.</p>
  <p>Going to the first controller I use:</p>
  <pre><code>let vc = FirstController()
  self.present(vc, animated: true, completion: nil)
  </code></pre>
  <p>And when in the other view controller I select the button that only dismisses I do this.</p>
  <pre><code>self.dismiss(animated: true, completion: nil)
  </code></pre>
  <p>So for the second controller that needs to dismiss and present another one I have tried the following:</p>
  <pre><code>self.dismiss(animated: true, completion: {
      let vc = SecondController()
      self.present(vc, animated: true, completion: nil)
  })
  </code></pre>
  <p>But I get an error:</p>
  <blockquote>
  <p>Warning: Attempt to present &lt;UINavigationController: 0xa40c790&gt; on &lt;IIViewDeckController: 0xa843000&gt; whose view is not in the window hierarchy!</p>
  </blockquote>