I have some subclasses of NSManagedObject generated using Xcode. I wrote some validation codes (validateForInsert:
) to those classes, but every time I update the data model and regenerate the subclasses, all those validation codes disappear. Some people suggest me to use categories to extend these classes instead of writing codes in it, but according to apple's document, overriding methods with categories is a very bad practice and can lead to undefined behaviour.
I also tried to subclass those generated classes. I have a generated class called DBEntityOne
and its subclass is called EntityOne
. EntityOne has an one-to-one relationship with EntityTwo, which is represented by DBEntityTwo
(generated) and EntityTwo
. However, whenever I try to get the EntityTwo associated with an EntityOne instance, what I get is a DBEntityTwo
instead of EntityTwo
.
So what should I do? Should I give up the automatic code generation and write all the entity classes by myself?