Last active
April 23, 2016 13:47
-
-
Save gravicle/f19fa2740158b8a3f4660a7c428408c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIApplication { | |
static var topViewController: UIViewController? { | |
var topVC = UIApplication.sharedApplication().keyWindow?.rootViewController | |
if let tabController = rootTabBarController { | |
topVC = tabController.selectedViewController | |
} | |
while(topVC?.presentedViewController != nil) { | |
topVC = topVC!.presentedViewController | |
} | |
if let navController = topVC as? UINavigationController { | |
topVC = navController.visibleViewController | |
} | |
return topVC | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment