Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Timers

A timer provides a way to perform a delayed action or a periodic action. The 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 a timer that sends a message to a window, telling it to update itself after a certain time interval. Timers are represented by NSTimer objects.

Timers work in conjunction with NSRunLoop objects. NSRunLoops control loops that wait for input, and they use timers to help determine the maximum amount of time they should wait. When the timer’s time limit has elapsed, the NSRunLoop fires the timer (causing its message to be sent), then checks for new input. Because of the various input sources a typical run loop manages, the effective resolution of the time interval for an NSTimer is limited to on the order of 50-100 milliseconds.

The run loop mode in which you register the timer must be running for the timer to fire. For applications built using the Application Kit, NSApplication runs the main thread’s run loop for you. On secondary threads, however, you have to run the run loop yourself. See Run Loops for details.



< Previous PageNext Page > Hide TOC


Last updated: 2002-11-12




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice