tags:

views:

68

answers:

1

I'm looking for a repeating timer object that allows me to create it once and then suspend and resume it as needed for the lifetime of my application.

I've seen documentation for NSTimer and although I think I can make it do what I want by building an abstraction on top of it that creates/invalidates timer objects multiple times, I was curios if there is a better way using some other system timer implementation. I'm not too familiar with Mac development and couldn't find any other leads besides NSTimer.

+1  A: 

Although NSTimer has no "suspend" method, [timer setFireDate:[NSDate distantFuture]] has that effect. To resume, use [timer setFireDate:[NSDate date]], or similar.

invariant
D'oh! It's right there in the doc for setFireDate.`You typically use this method to adjust the firing time of a repeating timer. Although resetting a timer’s next firing time is a relatively expensive operation, it may be more efficient in some situations. For example, you could use it in situations where you want to repeat an action multiple times in the future, but at irregular time intervals. Adjusting the firing time of a single timer would likely incur less expense than creating multiple timer objects, scheduling each one on a run loop, and then destroying them.`
psychotik