【问题标题】:addPersistentStoreWithType returns null (iOS, CoreData, iCloud)addPersistentStoreWithType 返回 null(iOS、CoreData、iCloud)
【发布时间】:2017-02-27 07:53:12
【问题描述】:

我有这个来自 CoreData 的 UIManagedDocument 我正在正确使用。 . .

NSURL *localUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
localUrl = [localUrl URLByAppendingPathComponent:@"Default Notes Database"];
//self.noteDatabase = [[UIManagedDocument alloc] initWithFileURL:localUrl]

现在我正在尝试在 iCloud 中保存核心数据的过程中创建 NSPersistentStore 实例。但是每当我尝试使用我的数据模型和 url 创建 NSPersistentStore 时,NSPersistentStore 总是为零。

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Notes" withExtension:@"momd"];
NSPersistentStoreCoordinator *migrationPSC = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]];

// Open the store
id sourceStore = [migrationPSC addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:iCloudUrl options:@{ NSPersistentStoreUbiquitousContentNameKey: @"InhoNotesiCloudStore",NSSQLitePragmasOption: @{@"journal_mode":@"DELETE"},NSMigratePersistentStoresAutomaticallyOption:@YES,NSInferMappingModelAutomaticallyOption:@YES } error:nil];

SourceStore 为零!为什么这是零?我搜索了答案,但在网上一无所获。

【问题讨论】:

    标签: ios core-data icloud


    【解决方案1】:

    问题是存储文件的路径错误 - 我发现使用模拟器应用程序文件进行调试。如果您创建带有或不带有 .sqlite 扩展名的 CoreData,则存储文件最终会位于应用程序文档文件夹中的不同位置。在我的情况下,我没有 .sqlite 扩展名,这意味着我的存储文件位于 Documents/Default Notes Database/storeContents/persistentStore 而不是 Documents/Default Notes Database.sqlite

    【讨论】:

      猜你喜欢
      • 2019-01-04
      • 2013-06-08
      • 1970-01-01
      • 2014-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多