1

我正在尝试将 iCloud 集成到我的旧项目中,但同时尝试使用 MagicalRecord 更新数据库。当我不使用自定义 .sqlite 文件名时,iCloud 可以工作,但不能使用自定义文件名。在这里,有一些代码可以更好地解释我的意思。

// Load model. Don't use the standard 'merged model' of Magical Record, because that would include
// the Ensembles model. Don't want to merge models.
NSManagedObjectModel *model = [NSManagedObjectModel MR_newManagedObjectModelNamed:@"Polyglott.momd"];
[NSManagedObjectModel MR_setDefaultManagedObjectModel:model];

// Setup Core Data Stack
[MagicalRecord setShouldAutoCreateManagedObjectModel:NO];

// This is the custom file name
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:@"PolyglottModel"];
// Here is the default one
// [MagicalRecord setupAutoMigratingCoreDataStack];

// Setup Ensemble

// Here, I'm not sure which one is the right way
NSURL *url = [NSPersistentStore MR_urlForStoreName:@"PolyglottModel.sqlite"];
// NSURL *url = [NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName]];

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Polyglott" withExtension:@"momd"];
self.cloudFileSystem = [[CDEICloudFileSystem alloc] initWithUbiquityContainerIdentifier:@"iCloud.de.thm.polyglott"];
self.ensemble = [[CDEPersistentStoreEnsemble alloc] initWithEnsembleIdentifier:@"PolyglottMR"
                                                            persistentStoreURL:url
                                                         managedObjectModelURL:modelURL
                                                               cloudFileSystem:self.cloudFileSystem];
self.ensemble.delegate = self;

// Listen for local saves, and trigger merges
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localSaveOccurred:) name:CDEMonitoredManagedObjectContextDidSaveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cloudDataDidDownload:) name:CDEICloudFileSystemDidDownloadFilesNotification object:nil];

[self syncWithCompletion:nil];

leechPersistentStoreWithCompletion 和 mergeWithCompletion 都给我任何错误,但是当我请求数据库时,没有数据。

有什么想法或例子吗?非常感谢你。

4

1 回答 1

0

我假设您已经查看了 Ensembles 中的 MagicalRecord 示例代码。

我不确定到底出了什么问题,但我猜你没有将正确的名称传递给MR_urlForStoreName:. 您可能应该放弃扩展名或类似的东西。通过设置断点并打印 URL 以查看它是否正确,应该很容易看到。

于 2016-05-18T19:13:11.153 回答