cannyboy
cannyboy

Reputation: 24426

Saving an image to the users preferences

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)

Upvotes: 1

Views: 473

Answers (2)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81868

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

[NSKeyedArchiver archiveRootObject:array toFile:[self dataFilePath]];

Upvotes: 3

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81868

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.

Upvotes: 0

Related Questions