Swift timer
March 8, 2015
This is a simple timer, using Swift.
var theTimer = NSTimer()
//function to start the timer (if needs be)
func startTimer() {
//start the timer with a 5 second delay
self.theTimer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector("timerIsDone"), userInfo: nil, repeats: false)
}
func stopTimer() {
//start the timer with a 5 second delay
self.theTimer.invalidate()
}
//The function called when the timer is done
func timerIsDone() {
println("Do something") stopTimer()
}
//start the timer - this can be in called as needed from another function or an init
startTimer()