With the dawn of ARC came a new main function template in xcode that makes a lot more sense. However, I have a question about the old template.
As everyone knows, the old main function template in XCode for Cocoa touch applications was this:
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
However, the last two lines are unreachable because the docs clearly state that UIApplicationMain never returns. It simply makes a call to exit() when it is done. So why did Apple opt for a template like this? Why not just this?
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
return UIApplicationMain(argc, argv, nil, nil);
}
Is it because people would take this as an example, and not release their autorelease pools properly? Or because it would trip up the static analyzer? Or something else possibly?
That question might be too open-ended so I will ask it another way. Is there a technical reason for using the template the way that Apple did?
Not a great answer but if you actually try your example then you get an
Unused variablewarning, which would be a bit slack to give everyone a warning with a freshly created project.