-3

Possible Duplicate:
How a runloop actually works

Hi

I have asked these two questions earlier, but yet I do not understand it.

Question about Runloops 1
Question about Runloops 2

In one of my iPhone-books they mention the run loop as this:

”Your application is one giant infinite loop called the run loop. The run loop’s job is to check for input (a touch, Core Location updates, data coming through a network interface, etc.) and find the appropriate handlers for that event (like an action or delegate method for an object).”

Okey, so where exactly is the loop? I know that the main application thread don’t need to run it and every thread has an associated run loop object however where is the actual loop portion of it? Is it a while loop that invisible surrounds the main-method, and if it where a loop that was looping wouldn’t that loop all of my code. I understand that this is wrong and it is not done though.

I do not understand the different modes a runloop can run in either, but maybe it is because I do not understand the runloop.

Thanks in advance!

Community
  • 1
  • 1
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434
  • 6
    The polite way to bring attention to existing questions is to post a bounty. Thanks. – sarnold Feb 20 '11 at 10:41
  • 2
    Or you can edit your question and add more detail. That'll bring it to the top of the heap. – Aurum Aquila Feb 20 '11 at 10:47
  • Ofcourse, I forgot that a bunch of you are just trying to get as much badges, points and whatever else that you can brag about. Thanks for let me have the chance to remove the question and paste it in my other one. Much appriciated. – LuckyLuke Feb 20 '11 at 12:19
  • Maybe you should have thought of that *before* you posted this, then, @Andreas. – Emil Feb 20 '11 at 12:54

1 Answers1

4

Take a look at the typical "main()" function for an iPhone (or any Cocoa, but Cocoa proper uses NSApplicationMain instead of UIApplicationMain) application:

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

This is the entire application, there is nothing unusual or "wrapped around" this main() routine. So, logically, you can conclude that the run loop is contained within the call to UIApplicationMain.

Bogatyr
  • 19,255
  • 7
  • 59
  • 72
  • That has actually always fascinated me, I've never really understood the `main`-function, it's so simple, but yet so brilliant. – Emil Feb 20 '11 at 13:36