Skip to content

Instantly share code, notes, and snippets.

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