Custom setter methods in Core-Data
        Posted  
        
            by andrewebling
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by andrewebling
        
        
        
        Published on 2010-06-04T05:51:20Z
        Indexed on 
            2010/06/04
            6:19 UTC
        
        
        Read the original article
        Hit count: 280
        
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?
© Stack Overflow or respective owner