2010-02-11 54 views

回答

4

当然,你的程序有main()功能就像任何C程序。一个新的Cocoa项目默认会调用NSApplicationMain(),但你可以根据需要进行其他操作。

如果你想轻松地访问从程序的其它地方的命令行信息,您可以使用_NSGetArgv()_NSGetArgc()_NSGetEnviron()_NSGetProgname()。他们宣布crt_externs.h

extern char ***_NSGetArgv(void); 
extern int *_NSGetArgc(void); 
extern char ***_NSGetEnviron(void); 
extern char **_NSGetProgname(void); 

这里有一个blog post有关这些功能,并以NSApplicationMaindocumentation的链接。

+2

+1我认为这是我第一次见到任何返回'char ***' – 2010-02-11 20:44:55

+1

@Dave它作为CharPtrArrayPtr更有意义,它仍然相当满意,但看起来不像Perlesque。 – 2010-02-13 02:12:00

+0

@Jeremy认为它是一个“指向字符串数组的指针”,这有助于我理解它。我主要困惑,为什么它不只是返回'char **'tho ... – 2010-02-13 06:07:30

2

你可能会发现更容易访问NSArgumentDomain在用户的默认值:

NSDictionary *const args = [[NSUserDefaults standardUserDefaults] 
          volatileDomainForName:NSArgumentDomain]; 

这将处理表单-NSZombieEnabled YES的论点。其他形式的参数(如-NSZombieEnabled=YES)可能会被忽略;我没有测试过或看过源代码。