Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cocoa GUI app invocation from CLI with arguments




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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Cocoa GUI app invocation from CLI with arguments (From: "Mac QA" <email@hidden>)
 >Re: Cocoa GUI app invocation from CLI with arguments (From: Jean-Daniel Dupas <email@hidden>)
 >Re: Cocoa GUI app invocation from CLI with arguments (From: "Mac QA" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.