On 11 Aug 2009, at 17:14, DeNigris Sean wrote:

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.

So file a bug report.

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.

The documentation barely specifies how parsing works for command line arguments at all. For instance, it's clearly the case that YES and NO work for boolean arguments. But that isn't documented anywhere and it means that if you want a string containing "YES" or "NO" you're going to be out of luck.

So I don't think it's a case of the behaviour not matching the spec. There *is* no spec worth mentioning, so really if there's a bug here, it's that the docs don't say how the argument domain works.

*Anyway*, my impression has always been that NSUserDefaults was not intended to be used to obtain the command line arguments, and that the argument domain feature was put there primarily (though perhaps not exclusively) for debugging purposes, as a way of temporarily overriding the settings in the defaults database.

If you want to process the command line arguments, you can either do so from your main() function, before calling NSApplicationMain(), or you can use NSProcessInfo to examine them once your app is running.

Kind regards,

Alastair.

--
http://alastairs-place.net



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to