FROM : George Orthwein
DATE : Sat Jul 15 07:36:10 2006
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
DATE : Sat Jul 15 07:36:10 2006
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






Cocoa mail archive

