Skip to content

Instantly share code, notes, and snippets.

@lanserxt
Created January 15, 2019 11:39
Show Gist options
  • Save lanserxt/2ddd370118bb92776ed75a6f48419960 to your computer and use it in GitHub Desktop.
Save lanserxt/2ddd370118bb92776ed75a6f48419960 to your computer and use it in GitHub Desktop.
UINavigationController extension to pop to specific class
extension UINavigationController {
func popToLastViewControllerType<T>(_ typeOfVC: T.Type) {
if let vc = viewControllers.last(where: {$0 is T}) {
popToViewController(vc, animated: true)
}
}
func popToFirstViewControllerType<T>(_ typeOfVC: T.Type) {
if let vc = viewControllers.first(where: {$0 is T}) {
popToViewController(vc, animated: true)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment