mercredi 21 janvier 2015

Save CoreData to iCloud (Swift)


Vote count:

0




I have already a CoreData, then now i want to save a data to iCloud.


In AppDelegate.swift



lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
var coordinator: NSPersistentStoreCoordinator =
NSPersistentStoreCoordinator (managedObjectModel: self.managedObjectModel)

var storeURL =
self.applicationDocumentsDirectory
.URLByAppendingPathComponent("DeviceCoreData.sqlite")

var storeOptions =
[NSPersistentStoreUbiquitousContentNameKey : "MyDevices"
// NSPersistentStoreRebuildFromUbiquitousContentOption: @(true)
]

//
self.registerCoordinatorForStoreNotifications (coordinator)

var error : NSError? = nil
var store : NSPersistentStore! =
coordinator.addPersistentStoreWithType (NSSQLiteStoreType,
configuration: nil,
URL: storeURL,
options: storeOptions,
error: &error)

if nil == store {
// handle error
}

return coordinator
}()

func registerCoordinatorForStoreNotifications (coordinator : NSPersistentStoreCoordinator) {
let nc : NSNotificationCenter = NSNotificationCenter.defaultCenter();

nc.addObserver(self, selector: "handleStoresWillChange:",
name: NSPersistentStoreCoordinatorStoresWillChangeNotification,
object: coordinator)

nc.addObserver(self, selector: "handleStoresDidChange:",
name: NSPersistentStoreCoordinatorStoresDidChangeNotification,
object: coordinator)

nc.addObserver(self, selector: "handleStoresWillRemove:",
name: NSPersistentStoreCoordinatorWillRemoveStoreNotification,
object: coordinator)

nc.addObserver(self, selector: "handleStoreChangedUbiquitousContent:",
name: NSPersistentStoreDidImportUbiquitousContentChangesNotification,
object: coordinator)
}


But when i build application, i got a error message



Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Ơn_Giời.AppDelegate handleStoresDidChange:]: unrecognized selector sent to instance 0x17668770'



Someone can help me ? I stack here 3 days.


And



[NSPersistentStoreUbiquitousContentNameKey : "MyDevices"]


This Key is correct or not ? My cloudkit named iCloud.MyDevices Thanks for your help...



asked 35 secs ago







Save CoreData to iCloud (Swift)

Aucun commentaire:

Enregistrer un commentaire