For the More Curious: Run Loop Observers

You can hook more stuff into the run loop, such as an observer. A run loop observer has its callback function invoked at a number of well defined places, shown Figure 15.6. These are the observation points:

  • When the run loop is entered

  • Before timers are fired

  • After timers are fired

  • Before sources (like the CFSocket) are checked

  • Before the run loop waits for activity (blocking until it can do something)

  • After it wakes up

  • When the run loop exits

Figure 15.6  Run loop observation points

Run loop observation points

Here is a function that will register an observer:

v​o​i​d​ ​a​d​d​R​u​n​L​o​o​p​O​b​s​e​r​v​e​r​ ​(​)​ ​{​ ​ ​ ​ ...

Get Advanced Mac OS X Programming: 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.