Responding to setters

Posted by Simon Cave on Stack Overflow See other posts from Stack Overflow or by Simon Cave
Published on 2011-01-17T05:47:16Z Indexed on 2011/01/17 5:53 UTC
Read the original article Hit count: 205

Filed under:
|

What is the best way to respond to data changes when property setters are called. For example, if I have a property called data, how can I react when [object setData:newData] is called and still use the synthesised setter. Instinctively, I would override the synthesised setter like so:

- (void)setData:(DataObject *)newData {
    // defer to synthesised setter
    [super setData:newData];

    // react to new data
    ...
}

...but of course this doesn't make sense - I can't use super like this. So what is the best way to handle this situation? Should I be using KVO? Or something else?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about cocoa