gpt4 book ai didi

objective-c - Cocoa:将参数传递给 NSApplicationDelegate

转载 作者:太空狗 更新时间:2023-10-30 03:12:20 28 4
gpt4 key购买 nike

我创建了简单的 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?
}

还有一些其他的。我怎样才能以正确的方式将 argc 和 argv 传递给我的 AppDelegate

最佳答案

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

在您的应用委托(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
}

关于objective-c - Cocoa:将参数传递给 NSApplicationDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5616959/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com