//
//  UIApplication.swift
//  Astro
//
//  Created by Anton Bielousov on 2015-09-16.
//  Copyright (c) 2015 Mobify Research & Development Inc. All rights reserved.
//

import Foundation

public extension UIApplication {
    @objc public var currentViewController: UIViewController? {
        // Start from the root viewcontroller for the application's key window
        // and then walk down the presentation tree until we find the last
        // presented view controller (that isn't being dismissed).
        var currentViewController = self.keyWindow?.rootViewController
        while currentViewController?.presentedViewController?.isBeingDismissed == false {
            currentViewController = currentViewController?.presentedViewController
        }

        return currentViewController
    }
}
