In a Cocoa application, user activities result in events.
These might be mouse clicks or drags, typing on the keyboard, choosing a menu
item, and so on. Other events can be generated automatically, for example a
timer firing periodically, or something coming in over the network. For each
event, Cocoa expects there to be an object or group of objects ready to handle
that event appropriately. The event loop is where such events are detected and
routed off to the appropriate place. Whenever Cocoa is not doing anything else,
it is sitting in the event loop waiting for an event to arrive. (In fact, Cocoa
doesn’t poll for events as suggested, but instead its main thread goes to
sleep. When an event arrives, the OS wakes up the thread and event processing
resumes. This is much more efficient than polling and allows other applications
to run more smoothly).
Each event is handled as an individual thing, then the event
loop gets the next event, and so on. If an event causes an update to be
required, this is checked at the end of the event and if needed, and window
refreshes are carried out.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
In a Cocoa application, user activities result in events. These might be mouse clicks or drags, typing on the keyboard, choosing a menu item, and so on. Other events can be generated automatically, for example a timer firing periodically, or something coming in over the network. For each event, Cocoa expects there to be an object or group of objects ready to handle that event appropriately. The event loop is where such events are detected and routed off to the appropriate place. Whenever Cocoa is not doing anything else, it is sitting in the event loop waiting for an event to arrive. (In fact, Cocoa doesn’t poll for events as suggested, but instead its main thread goes to sleep. When an event arrives, the OS wakes up the thread and event processing resumes. This is much more efficient than polling and allows other applications to run more smoothly).
Each event is handled as an individual thing, then the event loop gets the next event, and so on. If an event causes an update to be required, this is checked at the end of the event and if needed, and window refreshes are carried out.