Last active
June 14, 2018 07:43
-
-
Save Anatoli-Petrosyants/e7069f989180e2e68de387d6e4bfff58 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 { | |
class func topViewController(_ viewController: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? { | |
if let nav = viewController as? UINavigationController { | |
return topViewController(nav.visibleViewController) | |
} | |
if let tab = viewController as? UITabBarController { | |
if let selected = tab.selectedViewController { | |
return topViewController(selected) | |
} | |
} | |
if let presented = viewController?.presentedViewController { | |
return topViewController(presented) | |
} | |
return viewController | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment