Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kristiaand

macrumors member
Original poster
Dec 5, 2007
63
0
Hi everyone,
i would like some advice regarding storing files within the application bundle / package?

its more of a proof of concept at the moment than anything for a real application, i would like to know how to store a simple file inside the apps bundle / package that the user can dymanically update, and when the program closes and re-opens the users changes are kept.

so for example my program would open up and it would have a simple list of entries, this list can be edited by the user and when the program is re-opened the the list will reflect the users changes.

think of the mail.app which stores its email database within itself. but i do not want to go that mad with custom DB's etc, just a simple file will would be perfect.
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
You don't store files in the bundle. You store uneditable resources.

Mail doesn't store anything like the mail DB inside itself. It stores it in the user's Library folder. You should be doing the same. (Preferably under ~/Library/Application Support/Your App/)
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
It's best not to rely on that concept as your actual product would have to be radically reworked to support external file storage. Also your demo may be run off of a CD or a limited-access network share or some other medium where writing changes is not possible to the app's bundle.

You can make a set of "default" settings/preferences and store them in the app bundle and if/when the user makes changes you save those changes using the standard Preferences mechanism.

This way you can have the app present a pre-made set of behaviors out of the box without having to hard-code anything. And its easier to edit a plist file on the fly (before a demo) than having to rebuild the entire app).
 

kristiaand

macrumors member
Original poster
Dec 5, 2007
63
0
As normal lads you guys are brilliant, thanks for the information on this, something else that hit me just after reading the posts you gave was application updates, if they updated to a new version of that app they would loose all there customized settings etc.

thanks for stopping me from doing something monumentally dumb. would it be easier todo this sort of stuff using a core data application, rather than manually writing out all the code to read and write settings and prefs?

again thanks for the info.
 

Krevnik

macrumors 601
Sep 8, 2003
4,101
1,312
CoreData can probably do it pretty easily... but I would look at just using normal data classes to archive/unarchive, personally. An NSDictionary and its contents can be written out to disk and read back as long as all the objects support the right protocol (which would be work if you want to store custom objects, but if you are just using NS* objects, you should be fine).

If this is just user preferences, look at the NSUserDefaults class.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.