Last active
August 31, 2017 11:26
-
-
Save hashaam/f60d2220f187818c9a8979cc8975bdc6 to your computer and use it in GitHub Desktop.
UIWindow Presentation Context - Get top most presented UIViewController of UIWindow
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
// https://hashaam.com/2017/08/31/uiwindow-presentation-context/ | |
extension UIWindow { | |
func presentationContext(context: UIViewController? = nil) -> UIViewController? { | |
var presentationContextViewController = rootViewController | |
if let context = context { | |
presentationContextViewController = context | |
} | |
if presentationContextViewController?.presentedViewController == nil { | |
if let navigationController = presentationContextViewController as? UINavigationController { | |
return navigationController.topViewController | |
} | |
return presentationContextViewController | |
} | |
return presentationContext(context: presentationContextViewController?.presentedViewController) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment