I have been trying to pop my view controller to one of previous view controllers in my view stack. Assume that, There are firstVC, secondVC, thirdVC and fourthVC
Here you can do this by the find the controller from the UINavigationController stack and with the help of for loop and check the condition of your desire controller and if the condition gets fulfilled it will pop to the destionation controller.
let viewControllersStack: [UIViewController] = self.navigationController!.viewControllers
for firstViewcontroller in viewControllersStack
{
if firstViewcontroller is desireViewController
{
self.navigationController!.popToViewController(firstViewcontroller, animated: true)
}
}