Created
February 28, 2018 08:12
-
-
Save mukhortov/2f60328ad12ed1071c904669c6e7282e to your computer and use it in GitHub Desktop.
Visible ViewController UIViewController extension
This file contains hidden or 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
// | |
// UIViewController+VisibleViewController.swift | |
// | |
import Foundation | |
extension UIViewController { | |
func currentlyDisplayedViewController() -> UIViewController? { | |
if isKind(of: UINavigationController.self) { | |
let navigationController = self as! UINavigationController | |
return navigationController.visibleViewController?.currentlyDisplayedViewController() | |
} | |
if isKind(of: UITabBarController.self) { | |
let tabBarController = self as! UITabBarController | |
return tabBarController.selectedViewController?.currentlyDisplayedViewController() | |
} | |
if let presentedVC = presentedViewController { | |
return presentedVC.currentlyDisplayedViewController() | |
} | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment