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

I noticed in recent versions of Xcode, where ARC is used by default, the main.m Xcode file is generated for you when you start a new project, uses NSStringFromClass([AppDelegate class]) as a parameter for the application delegate in UIApplicationMain, and not 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 seems to me that it made me a little wise, but I hope that you are satisfied directly.

+7
source share
1 answer

This is a compilation check. This is better if the argument can be checked at compile time. If it is just a string, it cannot be verified.

Regarding the nil argument, the documentation says:

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

This assumes that you are using the xib file to declare the application delegate class. Well, many projects are not. As a rule, project templates without xib files (for example, "Empty Application") cannot use nil .

+9
source

All Articles