title: loop through array with delay - Swift
body: <p>Im trying to loop through an array, lighting up one color at a time, and once its finished looping through every item, calling another function to run. So far i have this:</p>
  
  <pre><code>//Delay function from http://stackoverflow.com/questions/24034544/dispatch-after-gcd-in-swift/24318861#24318861
  func delay(delay:Double, closure:()-&gt;()) {
      dispatch_after(
          dispatch_time(
              DISPATCH_TIME_NOW,
              Int64(delay * Double(NSEC_PER_SEC))
          ),
          dispatch_get_main_queue(), closure)
  }
  
  @IBAction func computerTurn(){
      if(isFirstLevel){levelLabel.text = ("Level 1"); isFirstLevel = false}
      else{ level++ }
  
      var gameOrderCopy = gameOrder
      var randomNumber = Int(arc4random_uniform(4))
      gameOrder.append(randomNumber)
      var i = 0
  
      for number in gameOrder{
  
          if number == 0{
              self.greenButton.highlighted = true
              self.delay(1){
                  self.greenButton.highlighted = false
                  }
          }
  
          else if number == 1{
              self.redButton.highlighted = true
              self.delay(1){
                  self.redButton.highlighted = false
                 }
  
          }
  
          else if number == 2{
              self.yellowButton.highlighted = true
              self.delay(1){
                  self.yellowButton.highlighted = false
                  }
          }
        else if number == 3{
          self.blueButton.highlighted = true
          self.delay(1){
              self.blueButton.highlighted = false
              }
          }
      }
  }
  </code></pre>
  
  <p>But at the moment, all it does is delay one second, then lighting up all the colors at once. What i need is to light up the color in sequential order, with a second delay between each. Thanks in advance!</p>