Mac Assigning NSManagedObject to NSPersistentStore

Hello,

I have a iOS app I was looking at porting to Mac.

I'm having an issue with both the Mac (Designed for iPad) and Mac Catalyst Destinations. I can't test Mac due to too many build issues.

I'm trying to assign a new NSManagedObject into a NSPersistentStore.

let object = MyObject(context: context)
context.assign(object, to: nsPersistentStore)

This works fine for iOS/iOS Simulator/iPhone/iPad. But on the Mac it's crashing with

FAULT: NSInvalidArgumentException: Can't assign an object to a store that does not contain the object's entity.; {
Thread 1: "Can't assign an object to a store that does not contain the object's entity."

The error indicates that current model version of the specified persistent store (nsPersistentStore) doesn't contain the entity of the object (MyObject). My best guess is that your Mac version is using a wrong model version – If that is not the case, I'd be interested in taking a closer look in case you can provide a minimal project that reproduces the error.

Best,
——
Ziqiao Chen
 Worldwide Developer Relations.

Mac Assigning NSManagedObject to NSPersistentStore
 
 
Q