Countdown timer

Create a variable Timer:
var timer = Timer()
var timeSet = 60
//this means the timer is for 60 seconds

Create 2 functions:
   @objc func updateTimer() {
        self.timeSet -= 1     //This will decrement(count down)the seconds.
        if(self.timeSet == 0)
        {
            self.dancewv.reload()
            continuePlaying()
        }

    }

 func runTimer() {
        timer = Timer.scheduledTimer(timeInterval: 1, target: self,   selector: (#selector(updateTimer)), userInfo: nil, repeats: true)
        
    }

In the function where you need the timer to run, call runTimer()

Comments

Popular posts from this blog

Setting up a playground

Go to another page