Given that I have rootViewController
which is UIApplication.shared.delegate?.window??.rootViewController
, I want to grab the active navigation controller, if any.
So far what I've come up with:
guard var controller = rootViewController?.presentedViewController else { return rootViewController as? UINavigationController }
while let presented = controller.presentedViewController {
controller = presented
}
controller = controller.navigationController ?? controller
return controller as? UINavigationController
Is this sufficient? A co-working gave me this solution but the part I don't understand is rootViewController?.presentedViewController
. Shouldn't it be rootViewController?.presentingViewController
?