I need to write a custom setter method for a field (we'll call it foo
) in my subclass of NSManagedObject
. foo
is defined in the data model and Xcode has autogenerated @property
and @dynamic
fields in the .h and .m files respectively.
If I write my setter like this:
- (void)setFoo: (NSObject *)inFoo {
[super setFoo: inFoo];
[self updateStuff];
}
then I get a compiler warning on the call to super
.
Alternatively, if I do this:
- (void)setFoo: (NSObject *)inFoo {
[super setValue: inFoo forKey: inFoo];
[self updateStuff];
}
then I end up in an infinite loop.
So what's the correct approach to write a custom setter for a subclass of NSManagedObject?
See Question&Answers more detail:os