Why does using the accessor -setFido: update the binding?


#1

On page 117, why does the following work?

[code]- (IBAction)incrementFido: (id)sender
{
// How/why does this work with bindings over just ++fido, though?!?!?
[self setFido: [self fido] + 1];
}

  • (void)setFido: (int)x
    {
    fido = x;
    }
    [/code]
    There isn’t any code in the -setFido: method to tell the KVC to update. I can see how using any of the -setValue:forKey: methods would update the bindings, but I don’t see how just using the -setFido: mutator method causes this update as well.

#2

[quote=“Glitch”]On page 117, why does the following work?

[code]- (IBAction)incrementFido: (id)sender
{
// How/why does this work with bindings over just ++fido, though?!?!?
[self setFido: [self fido] + 1];
}

  • (void)setFido: (int)x
    {
    fido = x;
    }
    [/code]
    There isn’t any code in the -setFido: method to tell the KVC to update. I can see how using any of the -setValue:forKey: methods would update the bindings, but I don’t see how just using the -setFido: mutator method causes this update as well.[/quote]

I think this is what’s going on behind the scenes -> mikeash.com/pyblog/friday-qa-2009-01-23.html


#3

[quote=“whoami”]I think this is what’s going on behind the scenes -> mikeash.com/pyblog/friday-qa-2009-01-23.html[/quote]Ahhhhhh… wow, that’s kind of sneaky of them. Makes sense to me now! Thanks, whoami! :smiley: