In Objective-C, there are three ways to create a timer. The
following two class methods automatically register the new timer
with the current NSRunLoop object in the default mode (NSDefaultRunLoopMode).
scheduledTimerWithTimeInterval:invocation:repeats:
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:
The following two class methods create timers that you may
register at a later time by sending the message addTimer:forMode: to
an NSRunLoop object.
timerWithTimeInterval:invocation:repeats:
timerWithTimeInterval:target:selector:userInfo:repeats:
Finally, you can allocate an NSTimer object yourself and send
it an initWithFireDate:interval:target:selector:userInfo:repeats: message.
This method allows you to specify an initial fire date independently
of the repeat interval. Unlike timers created with the previous
methods, this timer instance is not autoreleased, so you are responsible
for releasing it when you are done with it. Note that run loops
retain their timers, so you can release the timer after you have
added it to a run loop.
In Java, you create a timer with the NSTimer constructor, specifying the time interval, target, selector, user info, and whether the timer should repeat. You need to add the timer to the run loop yourself.
Once created, only the timer firing date can be modified,
using setFireDate:. All other parameters
are immutable after creating the timer.
If you specify that the timer should repeat, it automatically reschedules itself after it fires.
Last updated: 2002-11-12