Hi all,
You can use the NSTimer class to create timer objects or, more simply, timers. A timer can wait and call a method or selector after defined period of time. for example :- if you want show a seconds clock and stop when it completed 60 seconds then you can create a time with 1 second of period and turn on repeat mode , when defining selector method you have to specify some condition whenever you want to stop this timer.
Declaration :-
var timer: NSTimer?
Initialization :-
timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target:self, selector:"updateTimer", userInfo: nil, repeats:true)
Start Timer :-
NSRunLoop.currentRunLoop().addTimer(timer!, forMode:NSRunLoopCommonModes)
Defining Timer Selector :-
func updateTimer() {
//DO SOMETHING COOL
if CONDITION { // condition to stop timer
timer!.invalidate()
timer = nil
}
}
0 Comment(s)