Re: KVO and the observeValueForKeyPath bottleneck
Re: KVO and the observeValueForKeyPath bottleneck
- Subject: Re: KVO and the observeValueForKeyPath bottleneck
- From: George Orthwein <email@hidden>
- Date: Sat, 15 Jul 2006 01:36:10 -0400
Hi Matt,
Yeah I'm actually doing something similar though I wasn't aware of
NSSelectorFromString.
For a custom view that responds to a few dozen attributes of the
controller's current selection....
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
NSString *keyPathName;
if ([keyPath isEqualToString:@"selection.bgImage.color"] == YES){
// handle special case of this attribute of a relationship
keyPathName = @"bgImageColor";
} else {
// convert "selection.attribute" keypath to appropriate accessor
name -- by abusing pathExtension method :)
keyPathName = [keyPath pathExtension];
}
[self setValue:[object valueForKeyPath:keyPath] forKey:keyPathName];
}
So observing "selection.attribute" will call my setAttribute accessor
with the new value via KVC.
Possibly not the most proper setup, but it seems to work well enough
for this view's situation.
George
_______________________________________________
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