views:

937

answers:

4

i am working on a code which requires me to store 60*4 boolean values, the titles for these values are being stored in a plist. i require to manipulate the boolean values runtime and couldnt find a way to update the plist file easily..also using sqlite database for storing the boolean values becomes hectic for such large amount of data...is there any simple way in which i can store and retrive these valuse easily both runtime and after the application starts?

+1  A: 

Have a look at this SO question Possible to save an integer array using NSUserDefaults on iPhone?

epatel
thanks..this seem a reasonable solution...
Snehal
+7  A: 

I don't mean to be a heretic, but there's a simple rule for cases like this: premature optimization is the root of all evil.

60*4 is only 240 booleans. Even if you somehow manage to store them in the worst possible way and take 1k per boolean, that's still only 240k. As long as that's storage rather than RAM, who cares? Why not start with the simplest possible way and fix it when something comes to you later? SQLite would be perfectly fine for this.

If you're close to shipping and have identified this as a problem, by all means ignore this answer. :)

Steven Fisher
I have to agree. Worrying about 240 booleans is not the same as worrying about 240000 booleans. You try to pack them and the pack/unpack code will use up more space than the booleans themselves.
Nosredna
Actually for convience we had taken it 4 times but it can go to 100 also...so it will be 60*100 hence i was looking for some other way
Snehal
Well, storing 100 sets of 60 booleans (6000 total) in a sqlite3 database with an index and no optimization takes 150k.If the sets are always the same size, you could store them as strings of 60 bytes (+length) in indivdual records, but I think storing them individually is the better way to go.
Steven Fisher
+1  A: 

You could use the NSData method of storing the boolean array, but you could also just let cocoa do it naturally:

NSArray* arrayOfBools; // array of 240 NSNumbers, each made with [NSNumber numberWithBool:NO];

then

[[NSUserDefaults standardUserDefaults] setObject:arrayOfBools forKey:@"MyNameForThe240"];

Retrieve them:

NSArray* savedBools = [[[NSUserDefaults standardUserDefaults] objectForKey:"MyNameForThe240"];

You will likely want them in a mutable array:

NSMutableArray* the240ThatCanBeEdited = [NSMutableArray arrayWithArray:savedBools];

Then on quit, save them out with the [[NSUserDefaults standardUserDefaults] setObject:the240ThatCanBeEdited forKey:@"MyNameForThe240"];

--Tom

Tom Andersen
thanks...epatel also suggested the same and..this seem a reasonable solution...
Snehal