Re: Dependent values that are not iVars
Re: Dependent values that are not iVars
- Subject: Re: Dependent values that are not iVars
- From: Paul Bruneau <email@hidden>
- Date: Fri, 18 Dec 2009 14:48:58 -0500
On Dec 18, 2009, at 2:28 PM, Kyle Sluder wrote:
On Fri, Dec 18, 2009 at 11:18 AM, Paul Bruneau
<email@hidden> wrote:
if ([keyPath isEqualToString:kOverallWidth]) {
[self willChangeValueForKey:@"overallWidth"];
NSLog(@"got notification that overallwidth
changed:
%@", object);
[self didChangeValueForKey:@"overallWidth"];
}
Please note that it is not correct to call -will/didChangeValueForKey:
without actually changing the value. The KVO mechanism might just
simply not send a notification at all. (Well, I guess it's valid, but
you might see fewer observation notifications than you would expect.)
This is difficult to get right with derived properties.
Also don't have the first inclination I had, which is to use
-keyPathsForValuesAffectingValueForKey:. As described in the
documentation, it will not work.
Ugh, so I guess you are saying that derived properties are not
trustworthy in this usage?
I like them so much because then I never have to worry about the
stored value being out of date (which admittedly, if I do everything
exactly right, I guess it will never be out of date, but I like not
having to worry about it).
It's also a bummer because so far it is working fabulously with
willChange/didChange.
I might live dangerously and leave it in until it bites me.
Thanks for the warning, I'll make note of it.
_______________________________________________
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