I need to check if the back button is pressed in Swift. The action does not fire programmatically, so the approach appears to be to check if self is in the viewcontroller stack. I think the solution is here:
How to check for self with contains() in Swift?
However for each of the answers Swift tells me that contains is an unresolved identifier. I understand that is it in the Swift standard library so I assume I don't know how to use it.
Therefore what is the proper form of the following function?
override func viewDidDisappear(_ animated: Bool) {
if let viewControllers = self.navigationController?.viewControllers as? [UIViewController] {
if (contains(viewControllers, self)) {
print("Back button not pressed")
} else {
print ("Back button pressed")
}
}
}