Accessing command line arguments in Objective-C

2019-01-17 09:41发布

Is there any complete documentation (the interface is present in crt_externs.h) about this functions : _NSGetArgc and _NSGetArgv I can't get any documentation on the apple website about this functions.

3条回答
Deceive 欺骗
2楼-- · 2019-01-17 10:09

As those functions are prefixed with an "_", that's usually a sign that they are private, and not meant to be used by you. If you need to get the command line arguments, a better way to do it would be to look up NSProcessInfo.

查看更多
一纸荒年 Trace。
3楼-- · 2019-01-17 10:15

You can also access the commandline arguments using NSUserDefaults as described in the blogposts by Greg Miller or Alex Rozanski.

You basically get an NSUserDefaults instance through a call to [NSUserDefaults standardUserDefaults] and then use messages like boolForKey: or stringForKey: to access the values.

The official Apple documentation can be found here.

查看更多
爷、活的狠高调
4楼-- · 2019-01-17 10:16

If all you need to do is get the command line arguments in Cocoa, you can do:

NSArray *arguments = [[NSProcessInfo processInfo] arguments];
查看更多
登录 后发表回答