我注意到在默认使用 ARC 的最新版本的 Xcode 中,当您开始一个新项目时 Xcode 为您生成的 main.m 文件使用 NSStringFromClass([AppDelegate class])
作为UIApplicationMain 中应用程序委托(delegate)的参数,而不仅仅是 @"AppDelegate"
甚至只是 nil
新方式:
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
旧方法:
@autoreleasepool {
int retVal = UIApplicationMain(argc, argv, nil, nil);
return retVal;
}
我只是想知道是否有这样的原因?对我来说这似乎有点做作,但我希望一切顺利。
最佳答案
这是一个编译检查。最好能在编译时检查参数。如果它只是一个字符串,则无法检查。
关于 nil
参数,文档说:
Specify nil if you load the delegate object from your application’s main nib file.
假设您正在使用 xib 文件来声明应用程序委托(delegate)的类。好吧,很多项目都没有。通常,没有 xib 文件的项目模板(例如“空应用程序”)不能使用 nil
。
关于objective-c - 为什么 Xcode 使用 NSStringFromClass([AppDelegate class]) 而不是仅仅使用 @"AppDelegate"或 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14537202/