Re: KVO willChange and didChange
Re: KVO willChange and didChange
- Subject: Re: KVO willChange and didChange
- From: Jens Alfke <email@hidden>
- Date: Sun, 15 Jan 2012 23:13:02 -0800
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