navigationcontroller in swift pop two times
extension UINavigationController {
func popBack(_ nb: Int) {
let viewControllers: [UIViewController] = self.viewControllers
guard viewControllers.count < nb else {
self.popToViewController(viewControllers[viewControllers.count - nb], animated: true)
return
}
}
/// pop back to specific viewcontroller
func popBack<T: UIViewController>(toControllerType: T.Type) {
var viewControllers: [UIViewController] = self.viewControllers
viewControllers = viewControllers.reversed()
for currentViewController in viewControllers {
if currentViewController .isKind(of: toControllerType) {
self.popToViewController(currentViewController, animated: true)
break
}
}
}
}