Right now on my iPhone application I’m saving a large chunk of data from a NSData object to NSUserDefaults. I know that’s not the best approach because NSUserDefaults is meant only to store small pieces of data.
I’m doing this something like this:
NSData *data = [NSData alloc]init]];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"MyData"];
For late retrieval of this data.
What’s the correct way to save this data permanently for further use?
Make a custom class with the properties you want (.h file):
And then set the .m file up so that you can encode/decode the object
Then you can just
[NSKeyedArchiver archiveRootObject:obj toFile:[self saveFilePath]]to save and[NSKeyedUnarchiver unarchiveObjectWithFile:[self saveFilePath]]to load.This works for any kind of data, and gives you the option of adding as many different data files as you need to an object.