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
According to the documentation, it'd be:
- (void) setFoo:(NSObject *)inFoo {
[self willChangeValueForKey:@"foo"];
[self setPrimitiveValue:inFoo forKey:@"foo"];
[self didChangeValueForKey:@"foo"];
}
This is, of course, ignoring the fact that NSManagedObjects only want NSNumbers, NSDates, NSDatas, and NSStrings as attributes.
However, this might not be the best approach. Since you want something to happen when the value of your foo property changes, why not just observe it with Key Value Observing? In this case, it sounds like "KVO's the way to go".