0

Possible Duplicate:
Is there any reason to modify the main.m file in your iOS applications?

I am new in the iphone applications development and I want to know why we don't actively use the main.m file in the iphone programming. I saw in the many books the following usage:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:



    int main(int argc, char *argv[]) 
    {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
    }
Community
  • 1
  • 1
Anshuman
  • 25
  • 1
  • 6
  • 1
    exact duplicate - [Main.m file use in IPhone](http://stackoverflow.com/questions/4252952/main-m-file-use-in-iphone) and [Is there any reason to modify the main.m file in your iOS applications?](http://stackoverflow.com/questions/7998342/is-there-any-reason-to-modify-the-main-m-file-in-your-ios-applications) – beryllium Nov 09 '11 at 10:42

3 Answers3

3

iOS programs do start from a main() function, usually found in a file called main.m. You might have trouble locating this file, because it's normally in a group called Other Sources, not the Classes group where most code ends up.

In most iOS programs, main() does little more than call UIApplicationMain(), which creates the application object and runs the main event loop.

I don't know the precise details of why it's done like that, but I'll hazard a guess that a lot of framework-dependent stuff will break if you try to call it before the event loop gets going.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
  • i know but in the program we dont write any code on that file. My question is why we dont write any code on that file – Anshuman Nov 09 '11 at 10:41
0

The main.m is used just as an entry point for your application (it starts from there), the whole life cycle is handled in Objective C classes. The method application:didFinishLaunchingWithOptions:, that belongs to Application's delegate, is used to execute code once the app is ready.

ps: you should try to improve your english, since it's hard to read and understand :P

daveoncode
  • 18,900
  • 15
  • 104
  • 159
0

You can read about the main function here. It's not that you don't modify the main file, you do it very rarely. I have modified main function in past when I needed a custom UIApplication subclass.

int retVal = UIApplicationMain(argc, argv, @"CustomApplication", nil);

In general programming, you'd never need to modify the main class, however if you have any special requirements, you can go ahead and do that.

andih
  • 5,570
  • 3
  • 26
  • 36
Vin
  • 10,517
  • 10
  • 58
  • 71