0

I'd like to do away with XIB (Nib) files in my project, because that's just how I roll. However I'm finding that my AppDelegate class's method didFinishLaunchingWithOptions is never even called.

I tried setting the principal class in my app's main plist like so:

<key>NSPrincipalClass</key>
<string>AppDelegate</string>

This only leads to an error:

    +[AppDelegate registerForSystemEvents]: unrecognized selector sent to class 

So... how can I do without the principal class and just have my AppDelegate class run?

Thanks.

casperOne
  • 73,706
  • 19
  • 184
  • 253
  • I cover it inthe second half of this answer: http://stackoverflow.com/questions/7535605/where-is-your-application-delegate-set-and-who-initializes-its-window-and-viewco/7535776#7535776 – bryanmac Jan 14 '12 at 02:12
  • you also need to delete the reference to the .xib from into.plist – bryanmac Jan 14 '12 at 02:18
  • @"AppDelegate" is fragile - it will break if you rename your class. Use the NSStringFromClass() approach described in my answer to avoid this issue. – Conrad Shultz Jan 14 '12 at 02:20

2 Answers2

1

The easiest thing to do is just start with an appropriate project template... choosing "Empty Application" does not create a nib, but does properly setup you main.m with the following crucial line:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

I think registerForSystemEvents is a private method on UIApplication, which makes sense since the principal class should be UIApplication or subclass thereof, not a responder conforming to UIApplicationDelegate.

The UIApplicationMain() call above will set your principal class to UIApplication and the delegate to your custom AppDelegate class.

But as I said - just make life simple by using the appropriate project template.

Conrad Shultz
  • 8,748
  • 2
  • 31
  • 33
0

All C based programs need main.m, which is the starting point for all programs. You can choose a blank template, or you can just create your own. Though if you create your own you do need to make sure you've got an autorelease pool. You need to import your app delegate into main.m and I'm pretty sure you need UIKit as well. Then add the following code (replacing your app delegate class as needed:

int main(int argc, char *argv[])
    {
        int retVal = 0;
        @autoreleasepool {
            retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
        return retVal;
    }
Aaron Hayman
  • 8,492
  • 2
  • 36
  • 63