Created
October 29, 2018 07:19
-
-
Save cemolcay/9427ec538cbffe6f8de7afe6abb1ab43 to your computer and use it in GitHub Desktop.
Returns the top most child in a view controller.
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
import UIKit | |
extension UIViewController { | |
var topMostChild: UIViewController? { | |
if let tab = self as? UITabBarController { | |
return tab.selectedViewController?.topMostChild | |
} else if let nav = self as? UINavigationController { | |
return nav.topViewController?.topMostChild | |
} else if let split = self as? UISplitViewController { | |
return split.viewControllers.last?.topMostChild | |
} else if let presented = presentedViewController { | |
return presented.topMostChild | |
} | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment