Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nil-biribiri/2a7cb28bb16892d8af271ddd937ca085 to your computer and use it in GitHub Desktop.
Save nil-biribiri/2a7cb28bb16892d8af271ddd937ca085 to your computer and use it in GitHub Desktop.
UINavigationController extension for pop to specific view controller type + completion after pop (For push to new VC).
extension UINavigationController {
func popToViewControllerType<ViewControllerType: UIViewController>(_ type: ViewControllerType.Type,
animated: Bool = false,
completion: ((UINavigationController) -> Void)? = nil) {
for eachVC in self.viewControllers {
if eachVC.isKind(of: type.self) {
self.popToViewController(eachVC, animated: animated)
completion?(self)
break
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment