Hi Philip,
On Thu, 6 May 2004 18:37:12 +0200, Philip Motteli wrote:
Hi
Usually, every key-value operation, that is applied to an array, is
applied to its contents. So the array is actually transparent.
There are certain exceptions though:
@avg
@count
@distinctUnionOfArrays
@distinctUnionOfObjects
@max
@min
@sum
@unionOfArrays
@unionOfObjects
They are all marked by a preceding '@'. All these operators are sent
to> the array object itself and not to the objects it contains.
My question, proposal is: Why not use this '@' as a general mark, that
an operator should be sent to the array itself? Not restrict its use
to> these few mentionned predefined operators? This wouldn't be a
problem for code written for Cocoa. Cocoa would just> not have that
feature and (probably) raise an exception.
Or is there perhaps another way to do that and I'm just missing
something?
In a previous incarnation (EOF) of key-value coding you could add
-compute<Name>ForKey: methods in a category of NSArray, and these would
be made available as "@<name>" operators in -valueForKeyPath:
For example, one could implement:
@interface NSArray(MyCategory)
- (id)computeAtForKey:(NSString *)aKey;
...
such that it can subsequently be used like:
secondElement = [anArray valueForKeyPath:@"@at.2"];
or
nameOfThirdElement = [anArray valueForKeyPath:@"@at.3.name"];
I haven't checked that if this mechanism still works in the Mac OS X
10.3 Cocoa incarnation though...