Fix two problems with KVC:

- valueForKeyPath: looped over individual components, which meant classes couldn't override valueForKeyPath: to do multi-part keys (needed for operators)
- CPArray's valueForKeyPath: implementation was incorrectly parsing the operator if it was a simple key
This commit is contained in:
Ross Boucher committed 2010-02-12 12:53:15 -08:00
1 parent 72c36789c6
commit da84964a33
3 files changed
+28 -16

No files matched your search

+8 -9
View File
@@ -174,17 +174,16 @@ CPUnknownUserInfoKey = @"CPUnknownUserInfoKey";
- (id)valueForKeyPath:(CPString)aKeyPath
{
var keys = aKeyPath.split("."),
index = 0,
count = keys.length,
value = self;
var firstDotIndex = aKeyPath.indexOf(".");
for(; index < count; ++index)
value = [value valueForKey:keys[index]];
if (firstDotIndex === -1)
return [self valueForKey:aKeyPath];
return value;
var firstKeyComponent = aKeyPath.substring(0, firstDotIndex),
remainingKeyPath = aKeyPath.substring(firstDotIndex+1),
value = [self valueForKey:firstKeyComponent];
return [value valueForKeyPath:remainingKeyPath];
}
- (CPDictionary)dictionaryWithValuesForKeys:(CPArray)keys