views:

172

answers:

1

I think that sqlite3 is a little overkill in complexity for my purpose. I have a really tiny app that takes very tiny input from the user. Inputs are floating point values, dates and integers. I'd say even a hardcore user will generate not more than 10 kb of data with that app.

The object graph can be described pretty good with an calculator example. Imagine a calculator, that stores all calculations. Nothing cool/special. The object graph is like this: An NSMutableArray which stores instances of MyCalculationData objects. Every MyCalculationData object just stores simplest stuff: The mathematic operation used (identified by an integer that is mapped programmatically to something, i.e. "minus" or "division"), the entered value as CGFloat, a timestamp (just a big double, I think).

At the end, this whole NSMutableArray represents one session with that calculator, and the user can re-open it at any time. It gets stored in another NSMutableArray that holds all these calculation sessions.

In theory that's similar to what my app does.

So what are the options?

sqlite3: Too hard to use efficiently. Really. It's just hard, like trying to eat a 20 weeks old bread.

sqlite3 + FMDB: Sounds actually good. Having an objective-c wrapper class to get rid of all this c >> objective-c >> c conversions and restrictions. But: No documentation found. No examples found. No tutorials. Not much used / not much discussed.

CoreData: Maybe in one year, but not at this time. Don't believe in the statistics. Will not upgrade to 3.0 so fast.

Does anyone have good experience with one of those NSFooBarSerialization things?

+3  A: 

Have a look at NSKeyedArchiver/Unarchiver. As long as everything in your array conforms to the NSCoding protocol (NSStrings and NSNumbers already do) you can just save your array to disk like this:

NSData *data = [NSKeyedArchiver archivedDataWithRootObject:myArray];
[data writeToFile:@"/a/path/to/myFile" atomically:YES];

You can load it back like this:

NSData *data = [NSData dataWithContentsOfFile:@"/a/path/to/myFile"];
NSArray *myArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];

This method is simple and easy for simple applications such as yours.

iKenndac
sounds good!! Thanks mate.
HelloMoon