Up

NSTimer class reference

Authors

Andrew Kachites McCallum (mccallum@gnu.ai.mit.edu)
Richard Frith-Macdonald (rfm@gnu.org)

Date: Generated at 2023-12-20 19:35:39 -0500

Copyright: (C) 1995, 1996, 1999 Free Software Foundation, Inc.

Software documentation for the NSTimer class

NSTimer : NSObject

Declared in:
Foundation/NSTimer.h
Availability: OpenStep

An NSTimer provides a way to send a message at some time in the future, possibly repeating every time a fixed interval has passed. To use a timer, you can either create one that will automatically be added to the run loop in the current thread (using the -addTimer:forMode: method), or you can create it without adding it then add it to an NSRunLoop explicitly later.

NB. You may not use -init or +new to create a timer, as the timer must be properly initialised to send an action after some interval.


Instance Variables

Method summary

scheduledTimerWithTimeInterval: invocation: repeats: 

+ (NSTimer*) scheduledTimerWithTimeInterval: (NSTimeInterval)ti invocation: (NSInvocation*)invocation repeats: (BOOL)f;
Availability: OpenStep

Create a timer which will fire after ti seconds and, if f is YES, every ti seconds thereafter. On firing, invocation will be performed.
This timer will automatically be added to the current run loop and will fire in the default run loop mode.

scheduledTimerWithTimeInterval: repeats: block: 

+ (NSTimer*) scheduledTimerWithTimeInterval: (NSTimeInterval)ti repeats: (BOOL)f block: (GSTimerBlock)block;
Availability: OpenStep

Description forthcoming.

scheduledTimerWithTimeInterval: target: selector: userInfo: repeats: 

+ (NSTimer*) scheduledTimerWithTimeInterval: (NSTimeInterval)ti target: (id)object selector: (SEL)selector userInfo: (id)info repeats: (BOOL)f;
Availability: OpenStep

Create a timer which will fire after ti seconds and, if f is YES, every ti seconds thereafter. On firing, the target object will be sent a message specified by selector and with the timer as its argument.
This timer will automatically be added to the current run loop and will fire in the default run loop mode.

timerWithTimeInterval: invocation: repeats: 

+ (NSTimer*) timerWithTimeInterval: (NSTimeInterval)ti invocation: (NSInvocation*)invocation repeats: (BOOL)f;
Availability: OpenStep

Create a timer which will fire after ti seconds and, if f is YES, every ti seconds thereafter. On firing, invocation will be performed.
NB. To make the timer operate, you must add it to a run loop.

timerWithTimeInterval: repeats: block: 

+ (NSTimer*) timerWithTimeInterval: (NSTimeInterval)ti repeats: (BOOL)f block: (GSTimerBlock)block;
Availability: OpenStep

Description forthcoming.

timerWithTimeInterval: target: selector: userInfo: repeats: 

+ (NSTimer*) timerWithTimeInterval: (NSTimeInterval)ti target: (id)object selector: (SEL)selector userInfo: (id)info repeats: (BOOL)f;
Availability: OpenStep

Create a timer which will fire after ti seconds and, if f is YES, every ti seconds thereafter. On firing, the target object will be sent a message specified by selector and with the timer as its argument.
NB. To make the timer operate, you must add it to a run loop.

fire 

- (void) fire;
Availability: OpenStep

Fires the timer... either performs an invocation or sends a message to a target object, depending on how the timer was set up.
If the timer is not set to repeat, it is automatically invalidated.
Exceptions raised during firing of the timer are caught and logged.

fireDate 

- (NSDate*) fireDate;
Availability: OpenStep

Returns the date/time at which the timer is next due to fire.

initWithFireDate: interval: repeats: block: 

- (instancetype) initWithFireDate: (NSDate*)date interval: (NSTimeInterval)interval repeats: (BOOL)repeats block: (GSTimerBlock)block;
Availability: MacOS-X 10.12.0

Description forthcoming.

initWithFireDate: interval: target: selector: userInfo: repeats: 

- (id) initWithFireDate: (NSDate*)fd interval: (NSTimeInterval)ti target: (id)object selector: (SEL)selector userInfo: (id)info repeats: (BOOL)f;
Availability: MacOS-X 10.2.0

This is a designated initialiser for the class.
Initialise the receive, a newly allocated NSTimer object.
The ti argument specifies the time (in seconds) between the firing. If it is less than or equal to 0.0 then a small interval is chosen automatically.
The fd argument specifies an initial fire date copied by the timer... if it is not supplied (a nil object) then the ti argument is used to create a start date relative to the current time.
The f argument specifies whether the timer will fire repeatedly or just once.
If the selector argument is zero, then then object is an invocation to be used when the timer fires. otherwise, the object is sent the message specified by the selector and with the timer as an argument.
The object and info arguments will be retained until the timer is invalidated.

invalidate 

- (void) invalidate;
Availability: OpenStep

Marks the timer as invalid, causing its target/invocation and user info objects to be released.
Invalidated timers are automatically removed from the run loop when it detects them.

isValid 

- (BOOL) isValid;
Availability: MacOS-X 10.0.0

Checks to see if the timer has been invalidated.

setFireDate: 

- (void) setFireDate: (NSDate*)fireDate;
Availability: MacOS-X 10.2.0

Change the fire date for the receiver.
NB. You should NOT use this method for a timer which has been added to a run loop. The only time when it is safe to modify the fire date of a timer in a run loop is for a repeating timer when the timer is actually in the process of firing.

timeInterval 

- (NSTimeInterval) timeInterval;
Availability: MacOS-X 10.0.0

Returns the interval between firings, or zero if the timer does not repeat.

userInfo 

- (id) userInfo;
Availability: OpenStep

Returns the user info which was set for the timer when it was created, or nil if none was set or the timer is invalid.



Instance Variables for NSTimer Class

_block

@public GSTimerBlock _block;
Availability: OpenStep

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_date

@public NSDate* _date;
Availability: OpenStep

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_info

@public id _info;
Availability: OpenStep

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_interval

@public NSTimeInterval _interval;
Availability: OpenStep

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_invalidated

@public BOOL _invalidated;
Availability: OpenStep

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_repeats

@public BOOL _repeats;
Availability: OpenStep

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_selector

@public SEL _selector;
Availability: OpenStep

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.

_target

@public id _target;
Availability: OpenStep

Warning the underscore at the start of the name of this instance variable indicates that, even though it is not technically private, it is intended for internal use within the package, and you should not use the variable in other code.





Up