I have a class Base : NSManagedObject
generated by core data, and in order to add some methods to this entity, I subclass it with Derived : Base
. Now, I want to add a property (which is not in Base
class) to Derived
class. But when I try to access the setter of the added property, it throws an exception:
caught "NSInvalidArgumentException", "-[Base setAddedProperty:]: unrecognized selector sent to instance 0x7fdcc31b36d0"
Could anyone help?
EDIT: It seems that subclass of subclass of NSManagedObject cannot have its own methods because I just added a method to Derived
and got the similar exception. Does that mean category is the only way to add methods to subclass of NSManagedObject?
EDIT: I changed the "Class" of entities in configurations to Derived
and everything is working now. All those newly added properties can be accessed and customized methods can be invoked. Why? and is this a good practice?
EDIT: It seems the above descriptions are misunderstood. I intend to subclass the entity classes generated by core data in order to provide customized methods and properties, not to create child entities. Therefore, Derived
is not an entity in data model.