Cocoa: Pass arguments to NSApplicationDelegate
I have created the simple Cocoa application (Mac OS X开发者_StackOverflow中文版 10.6) and there have appeared the entry point:
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
and AppDelegate dummy:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// how to get argc and argv?
}
and some other. How could I pass the argc and argv to my AppDelegate right way?
Use +[NSProcessInfo processInfo] and -[NSProcessInfo arguments].
In your application delegate,
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSArray *args = [[NSProcessInfo processInfo] arguments];
// use -objectAtIndex: to obtain an element of the array
// and -count to obtain the number of elements in the array
}
加载中,请稍侯......
精彩评论