Re: Manual KVO and will/didChangeValueForKey
Re: Manual KVO and will/didChangeValueForKey
- Subject: Re: Manual KVO and will/didChangeValueForKey
- From: mmalcolm crawford <email@hidden>
- Date: Thu, 2 Jun 2005 18:25:41 -0700
On Jun 2, 2005, at 5:42 PM, Andrew White wrote:
- (void) makeAChange
{
[self willChangeValueForKey: @"property"];
<change property>
[self didChangeValueForKey: @"property"];
}
Is the property an instance variable? If so, you should implement
and use appropriate accessor methods.
- (void) observeValueForKeyPath: (NSString *) keyPath
ofObject: (id) object
change: (NSDictionary *) change
context: (void *) context
{
if (object == _a)
{
if ([keyPath isEqualToString: @"property"])
{
[self willChangeValueForKey: @"anotherProperty"];
[self didChangeValueForKey: @"anotherProperty];
return;
}
<...>
}
Umm, you can't just sprinkle your code with KVO notifications like a
magic incantation. Write and use appropriate accessor methods, and
if necessary register dependencies with
setKeys:triggerChangeNotificationsForDependentKey:. It may be the
case that there's still a problem after that, but it's much less
likely, and it will be a more structured problem to address.
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden