Skip to content

Instantly share code, notes, and snippets.

@hashaam
Last active August 31, 2017 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hashaam/f60d2220f187818c9a8979cc8975bdc6 to your computer and use it in GitHub Desktop.
Save hashaam/f60d2220f187818c9a8979cc8975bdc6 to your computer and use it in GitHub Desktop.
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