Post

Replies

Boosts

Views

Activity

Reply to Manually define a CKRecord ID for a given NSManagedObject instance
Hi DMG, I spent the last days implementing this solution to give you a proper feedback. Thank you so much for the direction, I've been able to separate the stores by using fetched properties relating the cloud entities to the local entities, just like the link pointed. But there's something weird happening when I access the fetched properties from a background context. In my Entity A (EA) I have a fetchedPropertyId of type String that refers to an id property on Entity B (EB). At the same EA I have the fetched property that has a predicate that points to EB and is the following: id == $FETCH_SOURCE.fetchedPropertyId The code to fetch the property in EA's class is: @NSManaged public var fetchedPropertyId: String? var fetchedProperty: EB? {     let value = value(forKey: "fetchedProperty")           let fetchedProperties = value as? [EB]           return fetchedProperties?.first   } Accessing eaInstance.fetchedProperty from the viewContext returns the correct values (nil if there's no fetchedPropertyId, and the correct item of type EB if fetchedPropertyId is defined). The weird thing is, whenever I access eaInstance.fetchedProperty in another context, the following error is thrown: [<NSTemporaryObjectID_default 0x7fe723f48070> valueForUndefinedKey:]: this class is not key value coding-compliant for the key fetchedPropertyId. This happens if I get the object by getting the objectID from the viewContext's managedObject instance and pass it to backgroundContext.object(with: objectID) and even if I fetch the given object again. Do you have any idea why is this happening?
Jul ’21