Re: NSUserDefault and Negative numerical arguments (Was: Posting mouse clicks with multiple displays)
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: DeNigris Sean <email@hidden>
- Date: Tue, 11 Aug 2009 12:14:18 -0400
In main.m:
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?
Yes-- -100 is parsed as an argument, not as a value to the previous
argument.
So, no, it isn't a bug. It is behaving correctly, for some values
of correct. Welcome to shell programming & the interface between
shell & process. Fragile space. Coder beware.
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.
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.
_______________________________________________
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