3
votes

I have entities prefixed with ICD_ in my Core Data Model. For each entity, I have a subclass which is prefixed with CD_. The subclasses which are prefixed with CD_ only implement static getters.

When I create an entity with MagicalRecord, I have to use the class prefixed with ICD_ not with CD_. Otherwise, I've got a SIGABRT:

"+entityForName: could not locate an entity named 'CD_User' in this model."

If I downcast my ICD_ entity to my CD_Entity it works in Objective-C. The same thing in Swift causes a SIGABRT. It's quite naturally because, it's the parent entity which is allocated, not the child class, so it's normally impossible to downcast it.

So I'm looking for a solution which permits to use my subclasses prefixed with CD_ with MagicalRecord.

1
If your CD_* subclasses implement static getters and nothing else, then why do you ever need to downcast?NRitH
I agree with you, in Objective-C it works, but in Swift it causes a SIGABRT.Jean Lebrument
It sounds like a bug in Obj-C, whereas Swift handles it correctly.NRitH
Try using categories instead of subclass to extend your entities.koen
Not if you keep the category in a separate source file.koen

1 Answers

0
votes

Either your data model is not loaded properly, or you are using an incorrect name to access the entities. You can see what names your data model contains by using the -entitiesByName method on NSManagedObjectModel