Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an event loop or run loop?

In iPhone development, I have come across these terms named

event loop, run loop

. Can some one explain explain what they are?

like image 277
RK- Avatar asked Oct 13 '10 05:10

RK-


2 Answers

Like many other GUI systems, the code you write for an iPhone application runs into a loop that is provided by the system. When writing a program without a GUI it is customary to have a main() function or similar. On iPhone you don't have that because it's provided by the system, and it will call the event loop. All you provide is callbacks to react to events.

The loop takes care of getting hardware events as touches and such, calling your code and API code to draw the windows, some memory management and all. This is why you never have to poll for these events yourself.

like image 112
Jean Avatar answered Oct 05 '22 20:10

Jean


I think this apple documentation will explains a little more:

An event loop is simply a run loop: an event-processing loop for scheduling work and coordinating the receipt of events from various input sources attached to the run loop. Every thread has access to a run loop. In all but the main thread, the run loop must be configured and run manually by your code. In Cocoa applications, the run loop for the main thread—the main event loop—is run automatically by the application object. What distinguishes the main event loop is that its primary input source receives events from the operating system that are generated by user actions—for example, tapping a view or entering text using a keyboard.

https://developer.apple.com/library/ios/documentation/General/Conceptual/Devpedia-CocoaApp/MainEventLoop.html

like image 43
CODE Avatar answered Oct 05 '22 19:10

CODE