It's true that the key-value store can only hold property list types. But you mentioned the objects in your array all conform to NSCoding
, so that's not a major problem. You just need to apply NSCoding
to convert your objects to/from NSData
, and store that.
Encode using
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:myObject];
Decode using
NSData *data = // from key-value store
MyClass *myObject = [NSKeyedUnarchiver unarchiveObjectWithData:data];
However if you're using UIDocument
, the key-value store is probably not the best way to go. You can also store and sync documents directly in iCloud via NSFileManager
and NSMetadataQuery
. Apple provides pretty good documentation on this, and it would sync the document in-place instead of requiring you to convert it back and forth. Plus of course, the key-value store has a very low total size limit while documents are only limited by the capacity of the user's iCloud account.