O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How Timers Work

Timers rely on the run loop to fire. When a timer is scheduled it calculates the next time that it should fire and asks the run loop to inform it when that time has arrived. NSTimer is fine for general purpose delays but is not suitable for cases where events must be fired with high resolution. It is documented to have a resolution on the order of 50-100ms.

For cases where timer resolution is not critical, NSTimer supports timer coalescing. By setting the tolerance property you can allow the system to massage the firing of all of the timers to happen at once, resulting in significant improvements in energy usage.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required