samedi 24 décembre 2016

if statement within a if statement in swift [duplicate]

This question is an exact duplicate of:

The following function counts down a red to green light, then counts the reaction time for the user to hit a button after the green light is displayed.

func updateCounter() {

timerInt -= 1
if timerInt == 2{
light.image = UIImage(named: "r.png")
 } else if timerInt == 1 {
light.image = UIImage(named: "yellow.png")


} else if timerInt == 0 {

light.image = UIImage(named: arc4random_uniform(2) == 0 ? "no.png" : "g.png")


timer.invalidate()
startStop.isEnabled = true
scoreTimer = Timer.scheduledTimer(timeInterval: 0.0001, target: self, selector: #selector(ViewController.updateScoreTime), userInfo: nil, repeats: true)

 }
}

how can i write the code so that when it states "else if timerInt == 0". The code will change timeIntervals depending on whatever arc4random images is chosen. So that when else if timerInt == 0 and no.png the time interval is 0.01 and when it states else if timerInt == 0 and g.png the time interval is 0.0001. Thanks

Aucun commentaire:

Enregistrer un commentaire