How to create an NSTimer

Timers are good if you want to delay executing a method, or if you need to call a method repeatedly. To set a one-off timer without setting a property you can use this:

However, you won’t be able to stop it without a reference. This is fine for one-off timers, but you need one if you want to stop a repeating timer.

To start a repeating timer self.myTimer:

And to stop if:

Here’s a working example on GitHub: https://github.com/versluis/TimerFun

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.