9

I have decided to load my views programmatically, so putting:

int ret = UIApplicationMain(argc, argv, nil, nil);

Would not work. I do have a ViewController and an AppDelegate, though. What would be the proper use of UIApplicationMain to use a ViewController and an AppDelegate.
PS I am NOT using XCode or Interface Builder, I am developing on the toolchain.

Mohit Deshpande
  • 48,747
  • 74
  • 187
  • 247

1 Answers1

16

This function is declared as

int UIApplicationMain (
   int argc,
   char *argv[],
   NSString *principalClassName,
   NSString *delegateClassName
);

Since you did not subclass UIApplication, pass nil to the 3rd argument. But you have a custom UIApplicationDelegate. So pass its class name to the 4th argument.

int retval = UIApplicationMain(argc, argv, nil, @"AppDelegate");
kennytm
  • 469,458
  • 94
  • 1,022
  • 977
  • What would be the benefit of subclassing UIApplication? – Mohit Deshpande May 26 '10 at 21:12
  • @Mohit: To replace some default behavior of UIApplication, e.g. `sendAction:to:from:forEvent:`. – kennytm May 26 '10 at 21:16
  • 16
    Replace @"AppDelegate" with NSStringFromClass([AppDelegate class]) to avoid the magic string in case you ever rename AppDelegate to something else. – George Feb 19 '11 at 16:59
  • @George Hm.... you probably meant to write `[appDelegate class]`, unless you capitalize your variable names. Or am I missing something? Surely you don't want the class name there but rather, the variable name. – Matt N. Jan 30 '13 at 13:50
  • @MattN. `AppDelegate` *is* the class name in his example. ;-) [Yes, this is a comment from the far future. :-p ] – Constantino Tsarouhas Oct 06 '13 at 16:30