how to prevent user response during delay before the AI response <p>I am having trouble with being able to keep activating buttons before my AI response in a Tic Tac Toe game. As you can see I added a delay response, but I am still able to do another turn even before my AI responds. Anyone knows how to disable the first player turn until the AI has made its turn?</p> <pre><code>@IBOutlet var userMessage: UILabel! struct Sender{ var tag = 1 } var plays = Dictionary&lt;Int,Int&gt;() var done = false var aiDeciding = false var sender: Sender = Sender() @IBAction func UIButtonClicked(sender:UIButton) { userMessage.hidden = true if plays[sender.tag] == nil &amp;&amp; !aiDeciding &amp;&amp; !done { setImageForSpot(sender.tag, player: 1) } checkForWin() func delay(delay:Double, closure:()-&gt;()) { dispatch_after( dispatch_time( DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC)) ), dispatch_get_main_queue(), closure) } delay(0.4) { self.aiTurn() } } </code></pre>