mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-09 10:20:59 +00:00
Add KVC+KVO support for "To Many" keys (i.e. Arrays).
This commit is contained in:
1 parent
490ad97f7b
commit
0b05b4b7d8
4 files changed
+648
-142
No files matched your search
@@ -278,81 +278,4 @@ CPUnknownUserInfoKey = @"CPUnknownUserInfoKey";
|
||||
|
||||
@end
|
||||
|
||||
//KVC on CPArray objects act on each item of the array, rather than on the array itself
|
||||
|
||||
@implementation CPArray (KeyValueCoding)
|
||||
|
||||
- (id)valueForKey:(CPString)aKey
|
||||
{
|
||||
if (aKey.indexOf("@") == 0)
|
||||
{
|
||||
if (aKey == "@count")
|
||||
return length;
|
||||
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newArray = [],
|
||||
enumerator = [self objectEnumerator],
|
||||
object;
|
||||
|
||||
while (object = [enumerator nextObject])
|
||||
{
|
||||
var value = [object valueForKey:aKey];
|
||||
|
||||
if (!value && value !== "")
|
||||
value = [NSNull null];
|
||||
|
||||
newArray.push(value);
|
||||
}
|
||||
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
|
||||
- (id)valueForKeyPath:(CPString)aKeyPath
|
||||
{
|
||||
if (aKey.indexOf("@") == 0)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
var newArray = [],
|
||||
enumerator = [self objectEnumerator],
|
||||
object;
|
||||
|
||||
while (object = [enumerator nextObject])
|
||||
{
|
||||
var value = [object valueForKeyPath:aKeyPath];
|
||||
|
||||
if (!value && value !== "")
|
||||
value = [NSNull null];
|
||||
|
||||
newArray.push(value);
|
||||
}
|
||||
|
||||
return newArray;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setValue:(id)aValue forKey:(CPString)aKey
|
||||
{
|
||||
var enumerator = [self objectEnumerator],
|
||||
object;
|
||||
|
||||
while (object = [enumerator nextObject])
|
||||
[object setValue:aValue forKey:aKey];
|
||||
}
|
||||
|
||||
- (void)setValue:(id)aValue forKeyPath:(CPString)aKeyPath
|
||||
{
|
||||
var enumerator = [self objectEnumerator],
|
||||
object;
|
||||
|
||||
while (object = [enumerator nextObject])
|
||||
[object setValue:aValue forKeyPath:aKeyPath];
|
||||
}
|
||||
|
||||
@end
|
||||
@import "CPArray_KVO.j"
|
||||
Reference in new issue
Block a user