Hello everyone,
I encounter a very strange bug/problem.
I'm syncing locally CloudKits objects with CoreData and AleCrim framework.
I have 2 entities in my core data model:
- Towns
- Restaurant
I have defined the relationship one to many and inverse. (yep, you've got it, a Town can have multiple restaurants ;))
I'm using the CoreData Stack to persist elements from CloudKit and the AlecrimCoreData library. In a class that grab content from ClouKit, I create the context thanks to Alecrim:
let dataContext = DataContext()Then I have a bunch of functions that call class functions that create if needed the NSManagedObjects
let town = Towns.createTownsFromCK(record, dataContext: self.dataContext) ... let restaurant = Restaurants.createRestaurantFromCK(record, dataContext: self.dataContext) ...As you can see I transmit the dataContext. So it's the same for Restaurants and Towns. CloudKit restaurant objects are grabbed after Towns have been locally saved.
do { try dataContext.save() } catch { }let restaurantPredicate = NSPredicate(format: "town == %@", record.recordID) let restaurantQuery = CKQuery(recordType: "Restaurants", predicate: restaurantPredicate) self.publicDB.addOperation(createQueryOperation(restaurantQuery, cursor: nil, resultblock:fetchedRestaurantsRecord))When grabbed, I can create restaurants NSManagedObject and add properties, but when I want to link the town, I have this strange error when I set the town:
if let cktownreference = record["town"] as? CKReference, town = dataContext.towns.filter({ $0.ckid! == cktownreference.recordID.recordName }).first { restaurant.town = town}The error (weird one...):
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unacceptable type of value for to-one relationship: property = "town"; desired type = Towns; given type = Towns; value = (entity: Towns; id: 0xd000000000080000 ; data: { ckid = "6665ca0f-af57-4305-8e18-ced7540e6279"; name = Paris; recordChangeTag = ii0l38hp; restaurant = ""; }).'
I have tried to create a new context, I have tried to set the Town NSSet, same results.
Here a re 2 screenshots of my model
Restaurant model & relationship
Town model & relationship
This problem is for every one-many link I have.
Thanks for your help.