Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Xcode use NSStringFromClass([AppDelegate class]) instead of just @"AppDelegate" or nil

I've noticed in recent versions of Xcode where ARC is used by default, the main.m file Xcode generates for you when you start a new project uses NSStringFromClass([AppDelegate class]) as the parameter for the app delegate in UIApplicationMain instead of just @"AppDelegate" or even just nil

New way:

@autoreleasepool {
      return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}

Old way:

  @autoreleasepool {
      int retVal = UIApplicationMain(argc, argv, nil, nil);
      return retVal;
  }

I'm just wondering if there is a reason for this? It just seems a bit contrived to me, but I'm hoping to be set straight.

like image 410
Toby Avatar asked Jan 26 '13 13:01

Toby


1 Answers

It's a compilation check. It's better if the argument can be checked at compile-time. If it's just a string, it's impossible to check.

Regarding the nil argument, the documentation says:

Specify nil if you load the delegate object from your application’s main nib file.

That supposes you are using a xib file to declare the class of your application delegate. Well, many projects don't. In general, project templates without xib files (e.g. "Empty Application") can't use nil.

like image 177
Sulthan Avatar answered Oct 18 '22 01:10

Sulthan