title: Use contains() to check if back button pressed in Swift
body: <p>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:</p>
  
  <p><a href="https://stackoverflow.com/questions/29954229/how-to-check-for-self-with-contains-in-swift">How to check for self with contains() in Swift?</a></p>
  
  <p>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.</p>
  
  <p>Therefore what is the proper form of the following function?</p>
  
  <pre><code>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")
          }
      }
  }
  </code></pre>