views:

400

answers:

2

I have looked for several hours for a good tutorial on how to store data for my command line program that I am writing in Objective-C. It seems like my options are NSUserDefaults, Plists, sqlite, or XML.

Now, I think at most I'd have 50kb of data to store, retrieve, and modify, so it seems like from what I read Plists would work just fine, but I'm having difficulty finding a good tutorial online. (I'm completely new to Objective C). Everything I find is for the iPhone, or NSUserDefaults - neither of which I'm looking for.

Can anyone point me in the right direction? I'm hoping just to replicate the very basic functionality of "defaults write com.yourcompanyname.yourappanme key data"

I would greatly appreciate a nudge in the right direction, but again, I'm completely new so the most basic tutorial is best.

A: 

The Property List Programming Guide is a good place to start.

The easiest way do do what you want is to put everything you want to save into an NSDictionary or NSMutableDictionary, and then use writeToFile:atomically: to save the data. You can read it back with initWithContentsOfFile:.

The property list guide linked above would rather you use NSPropertyListSerialization to generate an NSData object from the dictionary, and save that instead. That's a (little) bit more involved, but arguably a better approach.

Carl Norum
A: 

You actually might want to look into using Core Data: http://developer.apple.com/mac/library/documentation/cocoa/conceptual/CoreData/cdProgrammingGuide.html

It will let you save data in XML format.

christo16