NSTimer

NSTimer Mac OS X 10.0

This class represents a timer in the run-loop that can be used to invoke a method in a target after some elapsed time, or at regularly spaced intervals. The most straightforward way of creating a time is to use the method scheduledTimerWithTime-Interval:target:selector:userInfo:repeats:, which creates the timer and add it to the current run-loop in the default mode. To remove a timer from its run-loop and stopping it from firing again, send an invalidate message to the timer object.

NSTimer is toll-free bridged with the Core Foundation type CFRunLoopTimer. As such, NSTimer objects can be used interchangeably with the CFRunLoopTimer pointer type, CFRunLoopTimerRef.

The timer doesn't have good resolution; its accuracy is a function of the run-loop and what's on it.

figs/cocn_13110.gif

@interface NSTimer : NSObject
 // Convenience Constructors
   + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti invocation:(NSInvocation *)invocation
        repeats:(BOOL)yesOrNo;
   + (NSTimer *)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector
        userInfo:(id)userInfo repeats:(BOOL)yesOrNo;
 // Initializers
   - (id)initWithFireDate:(NSDate *)date interval:(NSTimeInterval)ti target:(id)t selector:(SEL)s
        userInfo:(id)ui repeats:(BOOL)rep;
 // Accessor Methods
   - (void)setFireDate:(NSDate *)date;
   - (NSDate *)fireDate;
 // Class Methods
   + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti invocation:(NSInvocation *)invocation          
        repeats:(BOOL)yesOrNo;
   + (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector
        userInfo:(id)userInfo repeats:(BOOL)yesOrNo;
 // Instance Methods
   - (void)fire;
   - (NSTimeInterval)timeInterval;
   - (void)invalidate;
   - (BOOL)isValid;
   - (id)userInfo;



    Part II: API Quick Reference
    Chapter 13. Foundation Classes