NSManagedObjects with categories

I find it common practice to create custom code for NSManagedObjectin the subclass category, since Xcode will override your generated subclass when editing the model. I just wanted to confirm it. I have seen examples where people say that it’s bad to combine categories with methods that are already implemented in the class hierarchy. I am not sure if this applies only to cases where a class that has an actual category has a method already implemented, or in all cases.

+2
source share
1 answer

The problem with overriding a method in a category is that you cannot invoke the original implementation, as usual, using [super doSomething]. Usually, when you redefine a method, you still want to be able to call the initial implementation that does something extra before and / or after the original implementation.

One pretty clean solution is to let Xcode generate subclasses of NSManagedObject that you don't directly touch. Instead, create another custom subclass of each subclass of NSManagedObject created by Xcode that you can edit without worrying about overwriting it.

Wolf Rentzsch mogenerator , Xcode . , , , mogenerator, , .

+3

All Articles