开发者

What is an event loop or run loop?

开发者 https://www.devze.com 2023-01-20 05:21 出处:网络
In iPhone development, I 开发者_如何学编程have come across these terms named event loop, 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 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消