Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Package | com.apple.cocoa.foundation |
Companion guides |
NSTimer creates timer objects or, more simply, timers. A timer waits until a certain time interval has elapsed and then fires, sending a specified message to a specified object. For example, you could create an NSTimer that sends a message to a window, telling it to update itself after a certain time interval.
If you specify in the constructor that the timer should repeat, it automatically reschedules itself after it fires. If you specify that the timer should not repeat, it is automatically invalidated after it fires.
To request the removal of a timer from an NSRunLoop, send the timer the invalidate
message from the same thread on which the timer was installed. This message immediately disables the timer, so it no longer affects the NSRunLoop. The NSRunLoop removes and releases the timer, either just before the invalidate
method returns or at some later point.
Returns an empty NSTimer.
public NSTimer
()
Creates a new NSTimer that, when added to a run loop, will fire after seconds.
public NSTimer
(double seconds, Object target, NSSelector aSelector, Object userInfo, boolean repeats)
Upon firing, the timer sends aSelector to target. The aSelector method must have the following syntax:
public void myTimerFireMethod(NSTimer* theTimer) |
The timer passes itself as the argument to aSelector. To pass more information to the target, use userInfo. The target gets userInfo by sending userInfo
to the timer.
If seconds is less than or equal to 0.0, this method chooses a nonnegative interval. If repeats is true
, the timer will repeatedly reschedule itself until invalidated. If repeats is false
, the timer will be invalidated after it fires.
Stops the receiver from ever firing again and requests its removal from its NSRunLoop.
public void invalidate
()
This is the only way to remove a timer from an NSRunLoop. The NSRunLoop removes and releases the timer, either just before the invalidate
method returns or at some later point.
You must send this message from the thread on which the timer was installed. If you send this message from another thread, the input source associated with the timer may not be removed from its run loop, which could prevent the thread from exiting properly.
Returns true
if the receiver is currently valid, false
otherwise.
public boolean isValid
()
Returns the receiver’s time interval.
public double timeInterval
()
Returns the userInfo object, containing additional data the target may use when the receiver is fired.
public Object userInfo
()
Do not invoke this method after the timer is invalidated. Use isValid
to test whether the timer is valid.
© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)