dimanche 27 août 2017

swift if statement, condition will never be executed

I thought I was good with if statements but apparently Im still missing something. In the following the timer.invalidate() line returns a "Will never be executed". As far as I can tell my syntax is correct.. xcode 9 beta6

@IBAction func button(_ sender: Any) {

        let timer = Timer.scheduledTimer(timeInterval:0.2 , target: self, selector: #selector(ViewController.imageSwitch) , userInfo: nil, repeats: true)

    var buttonState = false

    if buttonState == true {
        timer.invalidate()
        buttonState = false
    }
    if buttonState == false {
        timer.fire()
        buttonState = true
    }
}

Aucun commentaire:

Enregistrer un commentaire