Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a better way to put a bunch of stuff in NSUserDefaults?

I'm confused about NSUserDefaults on the iPhone.

I come from a C / asm background and the Objective-C stuff has been a learning experience.

I'm currently using NSUserDefaults to store some strings (for the names in a highscore table). I want to start implementing a "Save Game" type feature so if the user gets a call or exits out of the game for a moment, they can come back to it.

To recover the game, I've got a couple of BOOL flags, a couple of ints to store some necessary variables, but I'm stuck at an array I need to store.

I have a 50 element array of unsigned chars. I could move it to ints if it would make things easier, but I'm just not seeing it.

To work with NSUserDefaults I can setBool (already doing that), setFloat (again, already doing that), setInteger, and setObject.

Obviously I could declare keys for each element of the array and store them one by one with setInteger but that's really kludgy. What's the best way to tackle this? Instead of an array of unsigned chars, I somehow try to use an NSObject? Are there any good tutorials on NSObjects that I can read through to understand it better?

like image 983
K2Digital Avatar asked Jun 25 '09 03:06

K2Digital


1 Answers

Would Property Lists fit better with what you are trying to achieve?

You can create dictionary, store value for each setting or an array, and then dump it to Property List. You can easily read them back or update the values based on keys.

http://developer.apple.com/documentation/Cocoa/Conceptual/PropertyLists/...

like image 164
stefanB Avatar answered Sep 28 '22 02:09

stefanB