Timer can not find in scope

37 views Asked by At

Where is it wrong with this code?

@IBAction func startButton(_ sender: UIButton) {

    var timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(update), userInfo: nil, repeats: true)
}

@objc func update() {

    if (counter > 0) {

        print(counter)
        counter = counter - 1

        progreesBar.progress = 1.0 - Float(counter)/Float(seconds)
    } 
    else {
        timer?.invalidate()
    }
}

This code is not working as I expected. How can I fix it?

0

There are 0 answers