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
NSSQLiteStoreType
is a defined constant value. You need to use NSSQLiteStoreType
, not @NSSQLiteStoreType"
. Although NSSQLiteStoreType
is a string, its value is not @"NSSQLiteStoreType"
.