Move back to specific viewcontroller in swift

Use popToViewController to move back to specific viewcontroller

@objc func back(sender: UIBarButtonItem) {
    guard let navigationController = self.navigationController else { return }
var navigationArray = navigationController.viewControllers // To get all 
self.navigationController!.popToViewController(navigationArray[navigationArray.count - 2], animated: true)
}