title: What to use between performsegue and shouldperformsegue to execute segue if only the condition is TRUE
body: <p>I am having a hard time in solving my own issue regarding <code>segue</code>. The scenario should be when the user tapped the <code>backbutton</code> it will prompt an alert which will ask the user <em>Are you sure to leave this page?</em> <code>Leave</code> or <code>Stay</code> are the option. If the user tapped <code>Leave</code> response, it will go back to the <code>DashBoard</code> and if the user tapped <code>Stay</code> it will just retain to its original <code>ViewController</code>. The problem is the <code>segue</code> automatically executes without checking the condition inside the <code>backbutton</code>. I am new in swift and all issues I encountered and encountering are very new to me. How will I construct my codes correctly to meet the requirements of the <code>backbutton</code>. How will the button executes first the condition before it performs segue? Hope you can help me. Below are my codes for your reference. Been here for almost 1 week. Thank you.</p>
  
  <p><strong>performSegue</strong></p>
  
  <pre><code>  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
      if segue.identifier == "showDashBoard" {
          if let dashBoardVC = segue.destination as? DashBoardViewController {
              dashBoardVC.validPincode = validPincode
              dashBoardVC.participants = participants
              dashBoardVC.event = event
          }
      }
  }
  </code></pre>
  
  <p><strong>backbutton</strong></p>
  
  <pre><code> @IBAction func backbutton(_ sender: UIButton) {
  
      let alert = SCLAlertView(appearance: confirmationAppearance)
     _ = alert.addButton("Leave", action: {
          self.dismiss(animated: true, completion: nil)
      self.performSegue(withIdentifier: "showDashBoard", sender: sender)
      })
      _ = alert.addButton("Stay", action: { })
      _ = alert.showError("Confirmation", subTitle: "Are you sure you want to leave this page?")
  
      }
  </code></pre>
  
  <p><strong>trying to use shouldPerformSegue but I don't know how to start</strong></p>
  
  <pre><code>override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -&gt; Bool {
      if identifier ==  "showDashBoard" {
  
          var segueShouldOccur: Bool!
  
          if segueShouldOccur == false {
              print("nope, user wants to stay")
              return false
          }
          else {
              self.performSegue(withIdentifier: "showDashBoard", sender: sender)
              print("Yep, the user wants to leave")
          }
      }
  
  
      return true
  }
  </code></pre>
  
  <p><strong>screencapture for storyboard segue</strong>
  <a href="https://i.stack.imgur.com/f4Udu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f4Udu.png" alt="back button"></a></p>