[英]Ensembles: MagicalRecord and iCloud
我正在嘗試將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給我任何錯誤但是當我請求數據庫時,沒有數據。
任何想法或例子? 非常感謝你提前。
我假設您已經查看了Ensembles中的MagicalRecord示例代碼。
我不確定到底出了什么問題,但我猜你沒有把正確的名字傳給MR_urlForStoreName:
. 你可能應該放棄擴展或類似的東西。 通過設置斷點並打印URL以查看它是否正確應該很容易看到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.