Home > DeveloperSection > Interviews > Define Event Loop

Posted on    October-08-2015 12:46 AM

 iPhone iPhone  Ios  Objective C 
Ratings:
 1 Answer(s)
  419  View(s)
Rate this:

Tarun Kumar

Total Post:107

Points:535
Posted on    October-08-2015 12:46 AM

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.


Don't want to miss updates? Please click the below button!

Follow MindStick