• 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: NSUserDefault and Negative numerical arguments (Was: Posting mouse clicks with multiple displays)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSUserDefault and Negative numerical arguments (Was: Posting mouse clicks with multiple displays)


  • Subject: Re: NSUserDefault and Negative numerical arguments (Was: Posting mouse clicks with multiple displays)
  • From: Bill Bumgarner <email@hidden>
  • Date: Tue, 11 Aug 2009 10:00:28 -0700

On Aug 11, 2009, at 9:14 AM, DeNigris Sean wrote:
NSUserDefaults *args = [NSUserDefaults standardUserDefaults];

int x = [args integerForKey:@"x"];
int y = [args integerForKey:@"y"];
If the command line is "MyApp -x -100 -y 100", NSUserDefaults does not recognize the -100 as the value of the x argument - it sets x to 0. If the '-' is removed, everything is fine. Is this a bug? Is there a way around?

I consider that if a negative number is a valid value for an option, and NSUserDefaults can not handle them, and this restriction is not documented, then it's a bug.

But this has nothing to do with NSUserDefaults and everything to do with command line arguments.


When parsing the command line arguments, how does the application know that "-x means that the next argument must be parsed as a number"?

In short, it can't unless you use something somewhere to effectively express the schema of your command line arguments. Since there is no schema associated with NSUserDefaults, the problem can't be solved there.


Non-bug options would be:
a) handle negative arguments correctly
b) restrict numerical arguments to positive values and document this restriction


The behavior of the object does not match the spec.

It does. The spec simply does not encompass providing the schema necessary to parse the command line arguments.


See 'man getopt' then go google 'getopt better command line parsing'.

b.bum
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please 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


References: 
 >Re: NSUserDefault and Negative numerical arguments (Was: Posting mouse clicks with multiple displays) (From: DeNigris Sean <email@hidden>)

  • Prev by Date: UITabBarController Confusion
  • Next by Date: Re: NSUserDefault and Negative numerical arguments (Was: Posting mouse clicks with multiple displays)
  • Previous by thread: Re: NSUserDefault and Negative numerical arguments (Was: Posting mouse clicks with multiple displays)
  • Next by thread: NSDateFormatter formats from NSLocale
  • Index(es):
    • Date
    • Thread