Re: Saving/Opening Files - different under PB than with build of app
Re: Saving/Opening Files - different under PB than with build of app
- Subject: Re: Saving/Opening Files - different under PB than with build of app
- From: John Nestor <email@hidden>
- Date: Sun, 23 Dec 2001 01:44:15 -0500
Thanks for replies. Saving the file in a fixed location was just what
was needed.
Greg Titus wrote:
On Saturday, December 22, 2001, at 06:15 PM, John Nestor wrote:
I write a dictionary to file as follows: [theDictionary
writeToFile:@"foo" atomically:YES]; The file "foo"
appears in my build folder along with the build.
I read it back in using: [theDictionary withContentsOfFile:@"foo"];
The file is intended to be read in automatically on app launch and
saved automatically at termination.
The project is non document based
This works fine under PB. Also, FWIW examining "foo" with BBEdit
shows what I expect.
However, when I launch the build instead of running under PB the file
is not read in.
I fear I am missing something very fundamental but haven't been able
to ferret it out of the docs.
Appreciate any help.
All that you are missing is that the 'current directory' is different
when you are launched from ProjectBuilder vs. being launched from the
Finder. In PB it is the current app directory, in Finder it is "/".
Your app could also be launched from the command-line in which case
the current directory could be _anywhere_.
So, it's a very bad idea to depend in any way on what your current
directory is in an application. (I.e. use any paths that aren't
fully-qualified and start with a '/').
I suggest you either save the dictionary in NSUserDefaults instead, or
you use
"~/Library/Application Support/YourAppName/foo" (making sure that that
path exists and creating it if it doesn't, of course).
Hope this helps,
--Greg