views:

272

answers:

2

Has anyone had any experience in saving app preferences (within app, not in Settings app) which involve images taken with the camera?

The prefs include NSStrings, UIImage, BOOLs etc. The UIImage is a pic taken with camera.

Could I store these all in an NSMutableArray and then just do something like this:

[array writeToFile:[self dataFilePath] atomically:YES];

Can an array hold such variety of objects? (and BOOL is not strictly an object I guess)

+1  A: 

You can only write property lists using writeToFile:atomically:. This means, the array (and possible subcontainers) can only contain objects of type NSArray, NSDictionary, NSString, NSData, NSDate, and NSNumber. You have to convert your image to NSData, to use it in a property list.

Nikolai Ruhe
+3  A: 

You can save this array using the NSKeyedArchiver, avoiding the property list:

[NSKeyedArchiver archiveRootObject:array toFile:[self dataFilePath]];
Nikolai Ruhe
thanks. i will try both of your suggestions to see which works. With the NSKeyedArchiver technique, how would I load the values back in? Could I alloc/init an array, and do: [array unarchiveObjectWithFile:[self dataFilePath]]; ?
cannyboy
NSArray* array = [NSKeyedUnarchiver unarchiveObjectWithFile:pathToFile];
Nikolai Ruhe
I eventually used the 'UIImage > NSData' technique. Would there be an advantage in using the NSKeyedArchiver technique? Perhaps converting from UIImage to NSData and vice versa takes a little longer.
cannyboy