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

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
I will not have actual whole objects to save, just particular variables. They will be ints, floats and doubles. How do I do this?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Easiest way is to stick them in a NSDictionary (wrapped in NSValue/NSNumber objects if required) and save that via the obvious method.
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
hmm.... looking at the class doc it seems I'll have to wrap them in an NSNumber or NSValue, then an NSArray, THEN an NSDictionary. Seems like that's taking the long way... and it doesn't help that I haven't used NSDictionary or successfully saved an object or variable before. I'll look into it more but I'd like more suggestions please.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
I've no idea what you're using the array for. Create an NSMutableDictionary instance. Set each value you want to save for a sensible key. Write out via the writeToFile: method. No array...
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
When I don't care about tiny rounding errors, I just convert to string representation (sprintf), and write plain text files. Makes it much easier to dump the file to a text editor for debugging or printing, or for moving the data cross-platform.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
When I don't care about tiny rounding errors, I just convert to string representation (sprintf), and write plain text files. Makes it much easier to dump the file to a text editor for debugging or printing, or for moving the data cross-platform.

Whilst this approach is perfectly sensible it does take more code, especially to reload. We can reload the dictionary from a file with one line of code :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.