gpt4 book ai didi

core-data - Swift - 将支持 iCloud 的持久存储添加到核心数据

转载 作者:行者123 更新时间:2023-11-28 05:32:08 27 4
gpt4 key购买 nike

var appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
let documentsDirectory:NSURL = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL
let storeUrl:NSURL = documentsDirectory.URLByAppendingPathComponent("CoreData.sqlite")
var error:NSError?
let coordinator:NSPersistentStoreCoordinator = NSPersistentStoreCoordinator(managedObjectModel: appDel.managedObjectModel)
let storeOptions:NSDictionary = [NSPersistentStoreUbiquitousContentNameKey:"MyAppCloudStore"]
let store:NSPersistentStore = coordinator.addPersistentStoreWithType("NSSQLiteStoreType", configuration: nil, URL: storeUrl, options: storeOptions, error: &error)!
let finaliCloudURL = store.URL

这给我带来了一个错误:

2014-12-18 13:55:59.160 TestApp[1410:314557] CoreData: error: -addPersistentStoreWithType:NSSQLiteStoreType configuration:(null) URL:file:///Users/Bogdan-iMac/Library/Developer/CoreSimulator/Devices/29BD765A-1F4A-4C8A-8EAE-4AA0B1E91918/data/Containers/Data/Application/F19B3C5D-B6AD-4944-B4F3-BBBE4AF36D66/Documents/CoreData.sqlite options:{
NSPersistentStoreUbiquitousContentNameKey = MyAppCloudStore;
} ... returned error Error Domain=NSCocoaErrorDomain Code=134080 "The NSSQLiteStoreType persistent store type does not support iCloud integration." UserInfo=0x79fc9360 {NSLocalizedDescription=The NSSQLiteStoreType persistent store type does not support iCloud integration.} with userInfo dictionary {
NSLocalizedDescription = "The NSSQLiteStoreType persistent store type does not support iCloud integration.";
}
fatal error: unexpectedly found nil while unwrapping an Optional value

我在 Capabilities with Services:Key-value storage 中启用了 iCloud

最佳答案

NSSQLiteStoreType 是定义的常量值。您需要使用NSSQLiteStoreType,而不是@NSSQLiteStoreType"。虽然NSSQLiteStoreType是一个字符串,但它的值不是@"NSSQLiteStoreType".

关于core-data - Swift - 将支持 iCloud 的持久存储添加到核心数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27546250/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com