Pop to root view controller from modal
<p>I am trying to pop to the root view controller using the following code:</p>

<pre><code>self.navigationController!.popToRootViewController(animated: true)
</code></pre>

<p>This usually works, but I get an error when trying to use this code when the current view is a modal. How do I go about popping back to the root view controller in this situation?</p>

<p>Thanks in advance.</p>