With your code:
let viewController = navController.viewControllers[navController.viewControllers.count - 2]
let newController = self.storyboard!.instantiateViewController(withIdentifier: "Reservar")
You can be completely certain that the two view controllers are not the same object. They may or may not be the same type of view controller (the same class) but the function instantiateViewController()
always creates a brand-new, never-existed-before-this-moment, unique instance of the view controller. It might be an identical twin to another instance, with all the same settings, but it is still a unique object.
Tell us more about what you are trying to do. Are you looking to see if the object from the navigation controller is the type you are expecting?
Then you could use code like this:
let viewController = navController.viewControllers[navController.viewControllers.count - 2]
if viewController is ReservaViewController {
//code to operate on that type
} else {
//Code for other types of view controller
}
Or
if let viewController = navController.viewControllers[navController.viewControllers.count - 2] as? ReservaViewController {
//Code to operate on a ReservaViewController
} else {
//Code to deal with a view controller that's NOT a ReservaViewController
}
EDIT:
The expression navController.viewControllers[navController.viewControllers.count - 2]
is dangerous without range checking. If the navigation controller only contains 1 view controller, it will crash with an index out of range error.