Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: KVO and the observeValueForKeyPath bottleneck



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >KVO and the observeValueForKeyPath bottleneck (From: Matt Neuburg <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.