可可:将参数传递给NSApplicationDelegate [英] Cocoa: Pass arguments to NSApplicationDelegate

查看:220
本文介绍了可可:将参数传递给NSApplicationDelegate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created the simple Cocoa application (Mac OS X 10.6) and there have appeared the entry point:

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?

and some other. How could I pass the argc and argv to my AppDelegate right way?

推荐答案

使用+[NSProcessInfo processInfo]-[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
}

这篇关于可可:将参数传递给NSApplicationDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆