Skip to content

Instantly share code, notes, and snippets.

@leoShih
Last active July 11, 2018 20:40
Show Gist options
  • Save leoShih/ca07e4a3af02a8cf94373b830e4ba18f to your computer and use it in GitHub Desktop.
Save leoShih/ca07e4a3af02a8cf94373b830e4ba18f to your computer and use it in GitHub Desktop.
var startNumber = 240
var timer = Timer()
func runTime() {
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: (#selector(ViewController.tTimer)), userInfo: nil, repeats: true)
}
@objc func tTimer() {
if startNumber > 0 {
startNumber -= 1
numberLabel.text = String(startNumber)
}else{
timer.invalidate()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment