View Full Version : Question on NSTimer

Apr 21, 2009, 01:14 PM

Can someone point me in the right direction? I want to trigger an method when it hits a certain dynamic time that I set. For example at 9:00 PM today I want to call a method. The app will be running continuously. Would NSTimer be the best option for this? The only question I have with NSTimer would be what would my interval be, as the examples I've seen on NSTimer are intervals such as seconds or minutes. Is there a way to send NSTimer a future date?

Thanks for your help!!

Apr 24, 2009, 09:14 AM
Just set the interval on the timer to be the future date minus the current date (both in seconds). This is easy to do with -[NSDate timeIntervalSinceDate:]

Apr 24, 2009, 05:44 PM
or just use
- (id)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

of NSTimer

but in any case, I would be interested in what you are trying to do, since I can't imagine an app so great the user would keep it running all the time :D