O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required