• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Command line arguments...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Link Error: AESend defined in indirectly referenced dynamic library
      • From: Chuck Rice <email@hidden>
References: 
 >Command line arguments... (From: Jeff LaMarche <email@hidden>)

  • Prev by Date: Re: Develop with a Power/i Book
  • Next by Date: Link Error: AESend defined in indirectly referenced dynamic library
  • Previous by thread: Re: Command line arguments...
  • Next by thread: Link Error: AESend defined in indirectly referenced dynamic library
  • Index(es):
    • Date
    • Thread