Re: dictionaryWithContentsOfFile
Re: dictionaryWithContentsOfFile
- Subject: Re: dictionaryWithContentsOfFile
- From: Wade Tregaskis <email@hidden>
- Date: Mon, 24 May 2004 14:37:11 +1000
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? 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? 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).
When your app is run from XCode, the current directory is set to the
build directory by default. When it's run from the Finder (or anywhere
else), the current directory could be anything.
You need to look at NSBundle, specifically it's methods for dealing
with bundled resources. While you can request the path of your
application and work with it manually, you may find it a better
solution to simply request the named file of the appropriate type, and
let NSBundle deal with the details of locating it.
Wade Tregaskis (aim: wadetregaskis)
-- Sed quis custodiet ipsos custodes?
_______________________________________________
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.