I am new to CoreData and I'm trying to create a caching mechanism wherein after parsing objects from the API, I save them to the data model then fetch it again to show it on the tableview. I'm trying to fetch it using NSFetchedResultsController
. Upon initialization of the NSFetchedResultsController
, I'm encountering this runtime exception:
2018-12-09 15:03:20.493509+0800 [5184:148001] [error] error:
No NSEntityDescriptions in any model claim the NSManagedObject subclass
'Product' so +entity is confused. Have you loaded your
NSManagedObjectModel yet ?
CoreData: error: No NSEntityDescriptions in any model claim the
NSManagedObject subclass 'Product' so +entity is confused. Have you
loaded your NSManagedObjectModel yet ?
2018-12-09 15:03:20.493718+0800[5184:148001] [error] error: +
[Product entity] Failed to find a unique match for an
NSEntityDescription to a managed object subclass
CoreData: error: +[Product entity] Failed to find a unique match for an
NSEntityDescription to a managed object subclass
What could be the reason why?
My experience:
The entity class was missing the
@objc(Person)
line above the class name. I do have more classes that are working without this line but only when creating this specific entity, I have got this error.I came across the same issue when I changed the Codegen property of a Core Data Model to the type Category/Extension, to create a custom class for the Core Data Model.
As pointed out by @dypbrg, changing the following code segment
to the following code segment
seems to solve the issue.
In my case, I had changed the name of an entity and the swift-class but had forgot to update to the new swift-class name in the xcdatamodeld.
(In xcdatamodel view, under "CONFIGURATIONS" in the left pane, select "Default" and make sure the name of the classes are correct.)
If you ever encounter an issue similar to this using SwiftUI, you can try changing the entity's class module from Global Namespace to Current Product Module.
Go to your xcdatamodeld file and select the problematic entity. Then in the data model inspector, change the Module field from the default Global namespace to available value "Current Product Module" by clicking on the arrow at the right of the field.
This allowed my app to compile without encountering the error.