Background
I’m using the rather excellent mogenerator to auto generate my core data accessors.
mogenerator structures the classes as following:
NSManagedObject
_JGTrainingBase
JGTrainingBase
_JGTrainingGroup
JGTrainingGroup
-
Classes starting with an underscore are machine generated with core data accessors by mogenerator.
-
Classes without an underscore are human editable ones so you can put custom methods in there and not have it overwritten when you change your data model and rerun mogenerator.
-
The training group entity has to-many relationship called “children”.
-
I’m using the Core Data accessors to modify my relationships.
What I Want
I want to update duration – a transient attribute – before adding a children object.
The Problem
My Code
@implementation JGTrainingGroup
...
-(void)addChildrenObject:(JGTrainingGroup *)value_ {
[self updateDuration];
[super addChildrenObject:value_];
}
...
@end
But when I call this method, I get an error message:
[JGTrainingGroup addChildrenObject:]: unrecognized selector sent to instance 0x10667fa30
Generated Code
@interface _JGTrainingBase : NSManagedObject {}
// Method declarations
@end
@interface _JGTrainingBase (CoreDataGeneratedAccessors)
- (void)addChildrenObject:(JGTrainingBase*)value_;
- (void)removeChildrenObject:(JGTrainingBase*)value_;
// Lots more methods
@end
Questions
-
Why does super not respond to the addChildrenObject: method? Is it something to do with these being added in a category style?
-
How can I access the Core Data generated method from a subclass?
Note
I realise I can add the children object to the set using primitiveValueForKey: and similar, but that means I’m rewriting the core data accessors, thus wasting my time and probably making my code buggy. I trust Apple’s methods would be better than anything I could write.
Thanks for any input on helping me understand what’s going on here.
says ADC
You can not call super as those accessors are generated on demand by the runtime