Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension UIApplication {
- class func topViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
- if let nav = base as? UINavigationController {
- return topViewController(base: nav.visibleViewController)
- }
- if let tab = base as? UITabBarController {
- if let selected = tab.selectedViewController {
- return topViewController(base: selected)
- }
- }
- if let presented = base?.presentedViewController {
- return topViewController(base: presented)
- }
- if let vc = base as? NotificationShowable {
- return base
- }
- return nil
- }
- }
Add Comment
Please, Sign In to add comment