简体   繁体   English

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

[英]Swift - Adding an iCloud-Enabled Persistent Store to Core Data

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

That brings me an error: 那给我带来了一个错误:

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

I have enabled iCloud in Capabilities with Services:Key-value storage 我已在具有服务的功能中启用iCloud:键值存储

NSSQLiteStoreType is a defined constant value. NSSQLiteStoreType是定义的常量值。 You need to use NSSQLiteStoreType , not @NSSQLiteStoreType" . Although NSSQLiteStoreType is a string, its value is not @"NSSQLiteStoreType" . 您需要使用NSSQLiteStoreType ,而不是@NSSQLiteStoreType" 。尽管NSSQLiteStoreType是字符串,但其值不是@"NSSQLiteStoreType"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM