Name

NSTimer — Mac OS X 10.0

Synopsis

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.

image with no caption

@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 ...

Get Cocoa in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.