How to get the current displaying UIViewController not in AppDelegate?
<p>I'm trying to get the currently display <code>UIViewController</code> that is not in the AppDelegate, but it seems to always get the initial top <code>UIViewController</code>, and not the present one.</p>

<p>The following code in AppDelegate DOES get the current <code>UIViewController</code> present, but this same function does not work when I use it in any one of my View Controllers:</p>

<pre><code>func getTopViewController() -&gt; UIViewController
{
    var topViewController = UIApplication.sharedApplication().delegate!.window!!.rootViewController!
    while (topViewController.presentedViewController != nil) {
        topViewController = topViewController.presentedViewController!
    }
    return topViewController
}
</code></pre>

<p>The above code was provided as an answer in a similar question:
<a href="https://stackoverflow.com/a/40760970/2373410">Get the current displaying UIViewController on the screen in AppDelegate.m</a></p>

<p>No matter how deep down I segue to, I can only retrieve the first-most View Controller.</p>

<p>How can I get the current presenting <code>UIViewController</code>?</p>

<p>FYI: I'm <strong>NOT</strong> using a <code>UINavigationController</code>, just regular <code>UIViewController</code> classes.</p>