I am trying to save some user metadata in iCloud server Core Data SQLite. The documentation apparently says that in addition to the metadata it creates, I should be able to set my own metadata, similar to NSUserPreferences, but attached to my master data repository. Looks like it should be simple:
NSManagedObjectContext* moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[moc setPersistentStoreCoordinator:psc];
NSMutableDictionary* metadata = [[psc metadataForPersistentStore:store] mutableCopy];
metadata[@"testKey"] = @"testValue";
[psc setMetadata:metadata forPersistentStore:store];
[moc save:&error];
So, after that, my user key / metadata value is displayed in the store metadata field. However, when I restart the application, the metadata that I added no longer exists (but there is iCloud metadata). Please note that this works correctly when using regular storage without iCloud, therefore it is defined as iCloud.
Additional Information:
So, let's say I get metadata, add my custom fields and save them using static methods:
[NSPersistentStoreCoordinator setMetadata:metadata forPersistentStoreOfType:NSSQLiteStoreType URL:self.coreDataController.iCloudStore.URL error:&error];
NSDictionary* reviewMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:self.coreDataController.iCloudStore.URL error:&error];
The variable reviewMetadatacontains metadata with my fields added. However, as soon as I restart the application (and therefore reload the repository), it will return to how it was. I even tried to set a breakpoint and kill the application immediately after completing the above statements, and when I restart the application, my user metadata still disappeared.
Any ideas? Am I using metadata incorrectly? Does this work with iCloud-enabled vaults?
source
share