Events and the Run Loop

Most graphical user interface toolkits, including the Application Kit, use an event-driven model. That simply means applications react to events that are sent to the application by the operating system. The events can result from the user typing on a keyboard, or moving a mouse. Timer events can be sent at periodic intervals. The arrival or availability of any new data from a monitored input source is also conceptually an event.

Cocoa applications receive events from the operating system with the help of the NSRunLoop class. Every Cocoa application contains at least one instance of the NSRunLoop class. A run loop is created automatically for each thread in the application. In most cases, the programmer does not need to ...

Get Cocoa® Programming 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.