Cocoa bindings call valueForKey: instead of valueForKeyPath:
I have an NSPopUpButton that is attached to a subclass, with the following overridden methods:
- (id)valueForKeyPath:(NSString *)keyPath {
NSLog(@"valueForKeyPath: %@", keyPath);
if ([keyPath hasSuffix:@"availableVoices.name"]) {
return self.availableVoiceNames;
} else {
return [super valueForKeyPath:keyPath];
}
}
- (id)valueForKey:(NSString *)key {
NSLog(@"valueForKey: %@", key);
return [super valueForKey:key];
}
The links are as follows:
- Content -> Object .availableVoices
- Content Values -> Object.availableVoices.name
Instead of being called [Object valueForKeyPath:@"availableVoices.name"]
, valueForKey:
called for every key in a key. availableVoices
has no definition for name
, so it crashes.
Shouldn't you valueForKey:
be called after valueForKeyPath:
, if at all?
+3
source to share
1 answer