Re: KVO willChange and didChange
Re: KVO willChange and didChange
- Subject: Re: KVO willChange and didChange
- From: Roland King <email@hidden>
- Date: Mon, 16 Jan 2012 15:21:22 +0800
You missed this in the original mail.
"But the big thing for me is that I have a number of places throughout my application where I need to have the changes made, the didChange notification acted on by the observers, and then some other code run."
Which is why he wants to manually emit KVO notifications in a standardly-named setter so he can put more code after the didChangeValueForKey: before the setter returns.
I'd say having code which depends on that ordering is a bit suspect, but if that's what he wants, removing the automatic notifications and doing it himself is ok.
On 16 Jan, 2012, at 15:13, Jens Alfke <email@hidden> wrote:
>
> On Jan 15, 2012, at 10:41 PM, Gordon Henriksen wrote:
>
>> Try overriding +[NSObject(NSKeyValueObserving) automaticallyNotifiesObserversForKey:] to return NO for the properties you want to handle manually.
>
> Or just don’t call will/DidChange in your setter methods. You don’t need them there — KVO automatically does that for you when a setter is called.
>
> What will/DidChange are for is when you change a property’s value without invoking its setter. So if you had some code elsewhere that caused the value of the .foo property to change, you’d wrap those methods around the change. Obviously in your case you should just call setFoo instead, but there are cases when a property’s value isn’t stored explicitly as a variable, but is computed by the accessor method. So there’s no explicit variable and no sense in having a setter, but the value of the getter does change, and you have to let KVO know that.
>
> —Jens_______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden