• 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: Most elegant way to process command-line arguments in Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Most elegant way to process command-line arguments in Cocoa?


  • Subject: Re: Most elegant way to process command-line arguments in Cocoa?
  • From: Chris Suter <email@hidden>
  • Date: Thu, 8 Mar 2007 06:38:04 +1100


On 08/03/2007, at 6:26 AM, Diop Mercer wrote:

Hi. Is there a technique in Cocoa that someone can share that makes
processing command-line arguments as easy as in Perl?

For example, with this little bit of Perl code:

use Getopt::Std;
if (!getopts("f:t", \%args)) {
       usage();
}

the following happens when you run your Perl script:

1. if -f<somestring> or -f <somestring> appears on the command line,
either is accepted. You can have a space after the argument or not,
your preference. Either way, <somestring> magically winds up in the
hash variable %args, specifically in the hash bucket $args{'f'}.

2. if -t appears on the command line, it's considered a switch, and
the hash bucket $args{'t'} gets set to 1.



Is there a Cocoa equivalent to this?

Command-line arguments to Cocoa end up as user defaults so you access them via NSUserDefaults.


MyProg -MyArg <array><string>hello</string><string>there</string></ array>

well set a user default called MyArg to an array: { "hello", "there" }

Search the docs. for more information.

-Chris

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Most elegant way to process command-line arguments in Cocoa?
      • From: j o a r <email@hidden>
References: 
 >Most elegant way to process command-line arguments in Cocoa? (From: "Diop Mercer" <email@hidden>)

  • Prev by Date: Most elegant way to process command-line arguments in Cocoa?
  • Next by Date: Re: Most elegant way to process command-line arguments in Cocoa?
  • Previous by thread: Most elegant way to process command-line arguments in Cocoa?
  • Next by thread: Re: Most elegant way to process command-line arguments in Cocoa?
  • Index(es):
    • Date
    • Thread