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.

Get Cocoa Programming for OS X: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.