“Timer em Swift Stack Overflow” Respostas de código

Como eu tenho um cronômetro de contagem regressiva no Swift Stackoverflow

@IBAction func start(sender: UIButton) {
     self.timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(ViewController.update(_:)), userInfo: nil, repeats: true)
     NSRunLoop.currentRunLoop().addTimer(self.timer, forMode: NSRunLoopCommonModes)
    startTime = NSDate() // new instance variable that you would need to add.
}

func update() {
    let elapsedTime = NSDate().timeIntervalSinceDate(startTime)
    let currTime = totalTime - elapsedTime
    //total time is an instance variable that is the total amount of time in seconds that you want
    countDown.text = String(currTime)
    if currTime < 0 {
        timer.invalidate()
        //do other stuff that you need to do when time runs out.
    }
}
Grumpy Gaur

Timer em Swift Stack Overflow

var timer = NSTimer()
timer(timeInterval: 0.01, target: self, selector: update, userInfo: nil, repeats: false)
Grumpy Gaur

Respostas semelhantes a “Timer em Swift Stack Overflow”

Perguntas semelhantes a “Timer em Swift Stack Overflow”

Mais respostas relacionadas para “Timer em Swift Stack Overflow” em Swift

Procure respostas de código populares por idioma

Procurar outros idiomas de código