Tutorial by Examples

This will create a timer to call the doSomething method on self in 5 seconds. Swift let timer = NSTimer.scheduledTimerWithTimeInterval(5, target: self, selector: Selector(doSomething()), userInfo: nil, ...
Swift timer.fire() Objective-C [timer fire]; Calling the fire method causes an NSTimer to perform the task it would have usually performed on a schedule. In a non-repeating timer, this will automatically invalidate the timer. That is, calling fire before the time interval is up will result ...
Swift timer.invalidate() Objective-C [timer invalidate]; This will stop the timer from firing. Must be called from the thread the timer was created in, see Apple's notes: You must send this message from the thread on which the timer was installed. If you send this message from another thr...
Repeated Timer event Swift class ViewController: UIViewController { var timer = NSTimer() override func viewDidLoad() { NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector(self.timerMethod()), userInfo: nil, repeats: true) } func tim...
If you you want to pass some data with the timer trigger you can do it with the userInfoparameter. Here is the simple approach that gives brief idea about how you can pass the data to triggered method from the Timer. [Swift 3] Timer.scheduledTimer(timeInterval: 1.0, target: self, selector:#selec...

Page 1 of 1