, поэтому я успешно использую Magical Record с моим Core Data/iCloud. Вот как я инициализировать его:removeUbiquitousContentAndPersistentStoreAtURL Ошибка «Должен передать имя магазина» с помощью Magical Record
- (NSString *) iCloudContainerID {
return [NSString stringWithFormat:@"iCloud.%@", [[NSBundle mainBundle] bundleIdentifier]];
}
- (NSString *) localStoreName {
return @"test.sqlite";
}
- (NSString *) iCloudContentNameKey {
return @"test";
}
- (void) setupCoreDataWithiCloud {
NSString *containerID = [self iCloudContainerID];
DDLogiCloud(@"Setting up Core Data with iCloud");
[MagicalRecord setupCoreDataStackWithiCloudContainer:containerID
contentNameKey:[self iCloudContentNameKey] // Must not contain dots
localStoreNamed:[self localStoreName]
cloudStorePathComponent:@"Documents/CloudLogs" // Subpath within your ubiquitous container that will contain db change logs
completion:^{
// This gets executed after all the setup steps are performed
// Uncomment the following lines to verify
NSLog(@"%@", [MagicalRecord currentStack]);
// NSLog(@"%i events", [Event countOfEntities]);
}];
}
Используя код выше правильно устанавливает основные данные и ICloud. Наряду с некоторыми обработчиками уведомлений я могу добавлять записи локально в основные данные, а изменения распространяются на другие устройства через iCloud.
Во время тестирования было бы неплохо программно сбросить все. Это рутина я пытался сбросить CoreData/ICloud на основе яблок Docs: https://developer.apple.com/library/ios/documentation/DataManagement/Conceptual/UsingCoreDataWithiCloudPG/UsingSQLiteStoragewithiCloud/UsingSQLiteStoragewithiCloud.html#//apple_ref/doc/uid/TP40013491-CH3-SW33
- (bool) resetCoreDataWithiCloud {
NSString *containerID = [self iCloudContainerID];
NSURL *cloudURL = [NSPersistentStore MR_cloudURLForUbiqutiousContainer:containerID];
NSString *contentNameKey = [self iCloudContentNameKey];
NSDictionary *options = @{contentNameKey:NSPersistentStoreUbiquitousContentNameKey,cloudURL:NSPersistentStoreUbiquitousContentURLKey};
NSURL *storeURL = [NSPersistentStore MR_urlForStoreName:[self localStoreName]];
// NSURL *storeURL = [NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName];
// [MagicalRecord cleanUp];
DDLogiCloud(@"Resetting CoreData and iCloud named %@ at %@",containerID,storeURL);
NSError *error;
bool removeResult = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:storeURL options:options error:&error];
if (removeResult == NO) {
DDLogError(@"Could not remove iCloud Container. Reason: %@", error.localizedFailureReason);
}
return removeResult;
}
Независимо от того, что я стараюсь, вызов removeUbiquitous ... бросает ошибку «Должен пройти в магазин имя'.
Любое руководство по этому вопросу было бы полезно!