Re: Command line arguments...
Re: Command line arguments...
- Subject: Re: Command line arguments...
- From: Chris Parker <email@hidden>
- Date: Sun, 22 Jun 2003 17:09:08 -0700
Hi Jeff,
On Friday, June 20, 2003, at 8:04 PM, Jeff LaMarche wrote:
Does Cocoa provide a way to determine if command line arguments were
passed in (e.g. ./MyProgram.App -mySpecialFlag), or would you have to
subclass NSApplication to handle this?
There are a couple of ways to do this:
NSProcessInfo's -arguments message returns an NSArray containing the
argument list with NSStrings as the elements. If you require more
advanced parsing (like subcommands for your command line program, or
some such) you'll likely want to look at this.
NSUserDefaults parses out the arguments domain which allows you to just
use NSUserDefaults like so:
NSString * flagString = [[NSUserDefaults standardUserDefaults]
stringForKey:@"mySpecialFlag"];
And if an argument was provided, you'll get it in flagString. If not,
flagString will be nil (-boolForKey: works too - see the NSUserDefaults
documentation for more details).
This doesn't work if you just want the -presence- of '-mySpecialFlag'
on the command line to indicate "YES" - you'll have to explicitly
provide that.
.chris
--
Chris Parker
Cocoa Frameworks Engineer
Apple Computer, Inc.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.