Key-Value Observing: Further insight needed



on page 122 in the printed version, the reader is shown that, if one changes fido directly in the method incrementFido like this:

- (IBAction) incrementFido:(id)sender {
  fido = fido + 1;

the observers won’t get informed about the change. So far so good.
What I don’t understand is why it works if I do the following

- (IBAction) incrementFido:(id)sender {
  [self setFido:[self fido] + 1];

Since my setter setFido:(int)x does not have special code like willChangeValueForKey:@“fido”, there must be some kind of interceptor that realizes that a setter for fido was called. How is that accomplished?

Thank’s for the insight,


The short answer is that, yes, there are some special hooks being inserted that make the KVO magic work with setters. If you would like a long answer, I’d recommend this article (and blog in general): Friday Q&A 2009-01-23.


That’s certainly long enough :smiley: Thanks a lot.