Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UIWindow Presentation Context - Get top most presented UIViewController of UIWindow
// 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