这是我的代码模板:
int main(int argc, char *argv[]) {
// create an autorelease pool
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// make sure the application singleton has been instantiated
NSApplication * application = [NSApplication sharedApplication];
// instantiate our application delegate
AppDelegate * applicationDelegate =
[[[AppDelegate alloc] init] autorelease];
// assign our delegate to the NSApplication
[application setDelegate:applicationDelegate];
// call the run method of our application
[application run];
// drain the autorelease pool
[pool drain];
// execution never gets here ..
return 0;
}
“[pool drain]”后跟“return 0”为什么永远不会被执行。
但是,我发现了另一个 gnustep 官方示例,它做同样的事情。
int
main(int argc, char **argv, char** env)
{
id pool = [NSAutoreleasePool new];
NSApplication *theApp;
#if LIB_FOUNDATION_LIBRARY
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
#endif
theApp = [NSApplication sharedApplication];
[theApp setDelegate: [browserController new]];
[theApp run];
[pool release];
return 0;
}
为了证明它“[theApp run]”永远不会回来,我已经完成了在“[theApp run]”之后立即添加无限循环的练习。但它永远不会被执行。为什么 GNUSTEP 官方的示例会这样做?