Delay Button To Site

I have an alert that I want to go to a specific site but after the user presses okay and for it to show only once. I can't figure out the part where the site is delayed because the user did not press okay.

   var justOnce: Bool = true

   @IBAction func playStats(_ sender: Any) {
    //show alert only once
    if justOnce {
    let alert = UIAlertController(title: "Stats Important", message: "You can copy and paste the name here when you see the searchbar", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
    self.present(alert, animated: true, completion: nil)
    justOnce = false
    gotoSite()
    }
  }
Answered by Claude31 in 682109022

Call it in the button handler :

var justOnce: Bool = true

 @IBAction func playStats(_ sender: Any) {
  //show alert only once
  if justOnce {
  let alert = UIAlertController(title: "Stats Important", message: "You can copy and paste the name here when you see the searchbar", preferredStyle: .alert)
  alert.addAction(UIAlertAction(title: "OK",
                                style: UIAlertAction.Style.default,
                                handler: {_ in
                                    justOnce = false
                                    gotoSite()
                                } ))
  self.present(alert, animated: true, completion: nil)
  
  }
}
Accepted Answer

Call it in the button handler :

var justOnce: Bool = true

 @IBAction func playStats(_ sender: Any) {
  //show alert only once
  if justOnce {
  let alert = UIAlertController(title: "Stats Important", message: "You can copy and paste the name here when you see the searchbar", preferredStyle: .alert)
  alert.addAction(UIAlertAction(title: "OK",
                                style: UIAlertAction.Style.default,
                                handler: {_ in
                                    justOnce = false
                                    gotoSite()
                                } ))
  self.present(alert, animated: true, completion: nil)
  
  }
}
Delay Button To Site
 
 
Q