我尝试为自己的应用修改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.
有没有人遇到过此问题,我该如何解决?
答案 0 :(得分:2)
当您看到此错误时,您正在添加包含iCloud元数据的商店文件, 表示该文件已添加到iCloud。
添加iCloud商店时应添加选项:
NSDictionary *options =
@{ NSMigratePersistentStoresAutomaticallyOption:@(YES),
NSInferMappingModelAutomaticallyOption :@(YES),
NSPersistentStoreUbiquitousContentNameKey :self.iCloudCoreDataContentName,
NSPersistentStoreUbiquitousContentURLKey :self.iCloudCoreDataContentURL};
self.iCloudCoreDataContentName
(require)是您想要的任何名称,iCloud商店,名称
self.iCloudCoreDataContentURL
(可选)在iCloud容器中找到核心数据传输日志
此网址应该是iCloud容器的子目录,例如[[NSFileManager URLForUbiquityContainer:nil] URLByAddingComponent:@"CoreDataLogs"].
此属性在选项中是可选的。如果省略,iCloud CoreData内容URL将为[NSFileManager URLForUbiquityContainer:nil]
。
有关您应注意的网址和名称的更多详细信息: Xcode - "The provided ubiquity name is already in use" - how do I find a folder
如果您想将iCloud商店转变为本地商店,您可以在以下位置查看我的回答: How can I migrate the data from the iCloud store file to a new store file in local storage?