Swift 4:
Created an extension for UIViewController that can pop UIViewControllers in NavigationController stack depending in supplied number of times
extension UIViewController {
func pop(numberOfTimes: Int) {
guard let navigationController = navigationController else {
return
}
let viewControllers = navigationController.viewControllers
let index = numberOfTimes + 1
if viewControllers.count >= index {
navigationController.popToViewController(viewControllers[viewControllers.count - index], animated: true)
}
}
}