• 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: Launching Cocoa Application externally
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Launching Cocoa Application externally


  • Subject: Re: Launching Cocoa Application externally
  • From: Douglas Davidson <email@hidden>
  • Date: Thu, 15 May 2008 11:49:15 -0700


On May 15, 2008, at 11:45 AM, Jens Alfke wrote:

The problem was that I access a file (without proper error- handling; I will add that now :-)). The default working directory is the main-bundle path when run from within XCode and it is "/" when run from Finder.

I repaired this by adding
[[NSFileManager defaultManager] changeCurrentDirectoryPath:
[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]];
to my awakeFromNib. I hope this works as I intend.


That will work, although if any other -awakeFromNib method (of an object in that nib) wants to use a relative path, you have a race condition, because the order in which -awakeFromNib methods are called is, basically, random.

But it's better to just avoid using relative paths, if possible. If you're accessing a file inside your bundle, you should use the NSBundle resource APIs to get its location.

Let me echo what Jens said. The cwd is for command-line tools; don't use it, or anything that relies on it, in an application context, if you can do anything to avoid it.


Douglas Davidson

_______________________________________________

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: Launching Cocoa Application externally (From: Yann Disser <email@hidden>)
 >Re: Launching Cocoa Application externally (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Bypassing Interface Builder
  • Next by Date: Re: Query with PDF Page display in PDFview
  • Previous by thread: Re: Launching Cocoa Application externally
  • Next by thread: Cocoa and Carbon
  • Index(es):
    • Date
    • Thread