开发者

Cocoa: Pass arguments to NSApplicationDelegate

开发者 https://www.devze.com 2023-02-24 05:33 出处:网络
I have created the simple Cocoa application (Mac OS X开发者_StackOverflow中文版 10.6) and there have appeared the entry point:

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消