“Таймер в переполнении стека Swift” Ответ

Как у меня есть таймер обратного отсчета в 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

Таймер в переполнении стека Swift

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

Ответы похожие на “Таймер в переполнении стека Swift”

Вопросы похожие на “Таймер в переполнении стека Swift”

Больше похожих ответов на “Таймер в переполнении стека Swift” по Swift

Смотреть популярные ответы по языку

Смотреть другие языки программирования