Guest User

Untitled

a guest
Oct 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. extension UIApplication {
  2. class func topViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
  3. if let nav = base as? UINavigationController {
  4. return topViewController(base: nav.visibleViewController)
  5. }
  6. if let tab = base as? UITabBarController {
  7. if let selected = tab.selectedViewController {
  8. return topViewController(base: selected)
  9. }
  10. }
  11. if let presented = base?.presentedViewController {
  12. return topViewController(base: presented)
  13. }
  14.  
  15. if let vc = base as? NotificationShowable {
  16. return base
  17. }
  18. return nil
  19.  
  20. }
  21. }
Add Comment
Please, Sign In to add comment