Function

CFRunLoopTimerSetNextFireDate

Sets the next firing date for a CFRunLoopTimer object .

Declaration

void CFRunLoopTimerSetNextFireDate(CFRunLoopTimerRef timer, CFAbsoluteTime fireDate);

Parameters

timer

The run loop timer to modify.

fireDate

The new firing time for timer.

Discussion

Resetting a timer’s next firing time is a relatively expensive operation and should not be done if it can be avoided; letting timers autorepeat is more efficient. In some cases, however, manually-adjusted, repeating timers are useful. For example, if you have an action that will be performed multiple times in the future, but at irregular time intervals, it would be very expensive to create, add to run loop modes, and then destroy a timer for each firing event. Instead, you can create a repeating timer with an initial firing time in the distant future (or the initial firing time) and a very large repeat interval—on the order of decades or more—and add it to all the necessary run loop modes. Then, when you know when the timer should fire next, you reset the firing time with CFRunLoopTimerSetNextFireDate, perhaps from the timer’s own callback function. This technique effectively produces a reusable, asynchronous timer.

See Also

CFRunLoopTimer Miscellaneous Functions

CFRunLoopTimerCreateWithHandler

Creates a new CFRunLoopTimer object with a block-based handler.

CFRunLoopTimerCreate

Creates a new CFRunLoopTimer object with a function callback.

CFRunLoopTimerDoesRepeat

Returns a Boolean value that indicates whether a CFRunLoopTimer object repeats.

CFRunLoopTimerGetContext

Returns the context information for a CFRunLoopTimer object.

CFRunLoopTimerGetInterval

Returns the firing interval of a repeating CFRunLoopTimer object.

CFRunLoopTimerGetNextFireDate

Returns the next firing time for a CFRunLoopTimer object.

CFRunLoopTimerGetOrder

Returns the ordering parameter for a CFRunLoopTimer object.

CFRunLoopTimerGetTypeID

Returns the type identifier of the CFRunLoopTimer opaque type.

CFRunLoopTimerInvalidate

Invalidates a CFRunLoopTimer object, stopping it from ever firing again.

CFRunLoopTimerIsValid

Returns a Boolean value that indicates whether a CFRunLoopTimer object is valid and able to fire.