Re: Cocoa GUI app invocation from CLI with arguments
Re: Cocoa GUI app invocation from CLI with arguments
- Subject: Re: Cocoa GUI app invocation from CLI with arguments
- From: Chris Suter <email@hidden>
- Date: Tue, 1 Apr 2008 10:06:59 +1100
On 01/04/2008, at 9:40 AM, Mac QA wrote:
On 3/31/08, Jean-Daniel Dupas <email@hidden> wrote:
You can get cli arguments at anytime using NSProcessInfo.
- [[NSProcessInfo processInfo] arguments];
Awesome! This looks to be a much better method than parsing argv
inside main before calling NSApplicationMain, which is what I've
always done. Thanks!
I'm not sure it's such a good idea to process the arguments this way.
The problem is that Cocoa already uses arguments for its own purposes;
it allows you to set user defaults. A better bet, in my opinion, would
be to use the Cocoa way of passing arguments and then use
NSUserDefaults to access them. This also has the benefit of supplying
you with Cocoa objects rather than you having to parse them yourself.
See
<http://developer.apple.com/documentation/Cocoa/Conceptual/UserDefaults/Concepts/DefaultsDomains.html
>
The only awkwardness with doing it this way is if you don't like the
Cocoa way of passing arguments. If that's the case, I'd create a
separate tool to do what you want (perhaps just a wrapper around your
Cocoa application); I don't think you want to use your own argument
style with a Cocoa application unless you can find explicit
documentation that says it's safe to do so.
- Chris
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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