Cocoa:向NSApplicationDelegate传递参数

25

我创建了一个简单的Cocoa应用程序(Mac OS X 10.6),并出现了入口点:

int main(int argc, char *argv[])
{
    return NSApplicationMain(argc,  (const char **) argv);
}

AppDelegate占位符:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // how to get argc and argv?
}

还有其他的一些内容。我该如何正确地将argcargv传递给我的AppDelegate?

1个回答

36

使用+[NSProcessInfo processInfo]-[NSProcessInfo arguments]

在您的应用程序委托中,

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接