I want to show an alert with Confirmation when user clicks on back button. This is how I\'m trying to add action.
self.navigationItem.hidesBackButton = true
I don't know what you try to achive, but isn't it a possible solution to do, what you want, whenever vieWillDisappear: got called? This is maybe a matching entrypoint without fiddeling around with the back-bar-button suggested in the other answers.
Better
Another option would be to implement the UINavigationControllerDelegate, set your controller as delegate and then implement your alert in navigationController(_:willShow:animated:).
Take a look here for reference.