• 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: dictionaryWithContentsOfFile
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dictionaryWithContentsOfFile


  • Subject: Re: dictionaryWithContentsOfFile
  • From: Clark Cox <email@hidden>
  • Date: Mon, 24 May 2004 00:42:03 -0400

On May 23, 2004, at 23:17, James Stroud wrote:

Hello all,

I want to make a NSDictionary with the dictionaryWithContentsOfFile. Everything works fine when in XCode. I use the path @"MyApp.app/Contents/Resources/mydict.plist". But then it can't find the file when I move the build to the desktop (get a null). Where does my application think it is?

This has nothing to do with where the app thinks it is. When you specify a relative path (i.e. one that does not begin with a '/'), the filesystem interprets that as being relative to the current working directory (which for apps launched from the Finder is "/"). This is a common mistake (that I myself made several times), especially among those coming from Classic MacOS, where assuming that the working directory was that of the application was common.

To test this, I used writeToFile:atomically but couldn't find where it wrote the file when I moved the build. I found the file just fine when running with XCode (wrote into the "build" directory, one level above MyApp.app). I don't want to hard-code some of these dictionaries and would rather do by plist. Isn't this the point of a bundle?

Yes, that's the point of a bundle, so use the bundle APIs.
[[NSBundle mainBundle] pathForResource: @"mydict" ofType:@"plist"]
will give you the path to your plist file. This also has the advantage of giving you localization as well (i.e. you can have a different version of mydict.plist for each language that you wish to support, and the above code snippet will automatically return the path to the one that corresponds to the user's language.


I want the files in the .app directory and don't want to rely on an absolute path (or ~ path, for that matter). I want the files to never leave the bundle (read-only is fine).

--
Clark S. Cox III
email@hidden
http://homepage.mac.com/clarkcox3/
http://homepage.mac.com/clarkcox3/blog/B1196589870/index.html
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >dictionaryWithContentsOfFile (From: James Stroud <email@hidden>)

  • Prev by Date: NSImageView setAnimates - Does this work?
  • Next by Date: Re: dictionaryWithContentsOfFile
  • Previous by thread: dictionaryWithContentsOfFile
  • Next by thread: Re: dictionaryWithContentsOfFile
  • Index(es):
    • Date
    • Thread