Question on NSTimer

Discussion in 'iOS Programming' started by iamakimmer, Apr 21, 2009.

  1. iamakimmer macrumors newbie

    Apr 21, 2009

    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!!
  2. kainjow Moderator emeritus


    Jun 15, 2000
    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:]
  3. BlackWolf macrumors regular

    Apr 9, 2009
    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

Share This Page