0

我已经尝试为我自己的应用程序修改 Apple SharedCoreData 示例。

一切都(合理地)没问题,除了这个警告:

[NSPersistentStoreCoordinator addPersistentStoreWithType:configuration:URL:options:error:](1055): CoreData: Ubiquity:  
Error: A persistent store which has been previously added to a coordinator using the iCloud integration options must always be 
added to the coordinator with the options present in the options dictionary. 


If you wish to use the store without iCloud, migrate the data from the iCloud store file to a new store file in local storage. 
file://localhost/Users/david/Library/Containers/.../Data/Documents/SharedCoreDataStores/localStore.sqlite

This will be a fatal error in a future release.

有没有人遇到过这个问题,我该如何解决?

4

1 回答 1

2

当您看到此错误时,您正在添加包含 iCloud 元数据的存储文件,这意味着该文件已添加到 iCloud。

添加 iCloud Store 时应添加选项:

        NSDictionary *options =
        @{  NSMigratePersistentStoresAutomaticallyOption:@(YES),
        NSInferMappingModelAutomaticallyOption      :@(YES),
        NSPersistentStoreUbiquitousContentNameKey   :self.iCloudCoreDataContentName,
        NSPersistentStoreUbiquitousContentURLKey    :self.iCloudCoreDataContentURL};

self.iCloudCoreDataContentName(require) 是您想要的任何名称、iCloud 商店、名称

self.iCloudCoreDataContentURL(可选)在 iCloud 容器中定位核心数据传输日志

这个 URL 应该是 iCloud 容器的子目录,比如[[NSFileManager URLForUbiquityContainer:nil] URLByAddingComponent:@"CoreDataLogs"].

此属性在选项中是可选的。如果您省略它,iCloud CoreData 内容 URL 将为[NSFileManager URLForUbiquityContainer:nil].

有关您应该注意的 URL 和名称的更多详细信息: Xcode - “提供的通用名称已在使用中” - 我如何找到文件夹

如果您想将 iCloud 存储转换为本地存储,您可以在以下位置查看我的答案: 如何将数据从 iCloud 存储文件迁移到本地存储中的新存储文件?

于 2012-12-27T14:34:16.130 回答