How can I make a countdown with NSTimer?

后端 未结 15 1670
遇见更好的自我
遇见更好的自我 2020-11-30 03:17

How can I make a countdown with an NSTimer using Swift?

15条回答
  •  心在旅途
    2020-11-30 03:48

    this for the now swift 5.0 and newst

    var secondsRemaining = 60
    
    
    Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateCounter), userInfo: nil, repeats: true)
    }
    @objc func updateCounter(){
        if secondsRemaining > 0 {
        print("\(secondsRemaining) seconds.")
        secondsRemaining -= 1
                }
            }
    

提交回复
热议问题