Johnny Cherries
Johnny Cherries

Reputation: 35

NSDictionary (storing view controllers) in iCloud

My view controllers have a lot of bools, strings and ints that they save with NSCoding, and then a couple of classes save more of the same kind of information. I tie it all together by putting the view controllers in an NSMutableDictionary and saving it with NSKeyedArchive.

NSMutableDictionary *rootObject;
rootObject = [NSMutableDictionary dictionary];
[rootObject setValue:self.controllers forKey:@"controllers"];
[NSKeyedArchiver archiveRootObject:rootObject toFile:path];

Using NSKeyedUnarchiver to set the view controllers brings back all of their NSCoded data and it works well.

I'm looking at implementing iCloud and am confused about the best way to go about it. If I store the NSMutableDictionary in a UIDocument class specifically made for saving and then load it up, will it carry the NSCoded values over?

Upvotes: 0

Views: 224

Answers (1)

matt
matt

Reputation: 535890

Archiving simply means turning something into an NSData object. An NSData object is an NSData object. It will not mysteriously lose its integrity because it was stored in the cloud. If it worked when unarchived from wherever you have been keeping it (e.g. user defaults, a file on disk, etc.), it will work when you unarchive it from the cloud.

You might not need the overhead of UIDocument. Keep in mind that iCloud effectively lets you keep the equivalent of NSUserDefaults-type data in the cloud ("key-value storage") - and it doesn't count against the user's 5MB limit.

Upvotes: 2

Related Questions