Skip navigation.
 
mlRe: valueForKey and NSArray
FROM : Michael Ash
DATE : Sun Jun 25 19:40:46 2006

On 6/24/06, YL <<email_removed>> wrote:
> But I don't know how to state "do it as usual" in code:-(
>
> @implementation NSArray (keyPath)
> - (id) valueForKey:(NSString *)aKey;
> {
>    if([aKey isEqual:[NSString stringWithFormat:@"%d",[aKey intValue]]]) {
>        if([self count] > [aKey intVaue])
>            return [self objectAtIndex:[aKey intValue]];
>        return  RETURNVALUE_AS_USUAL;
> }
> @end


"Do it as usual" is generally done by invoking super's implementation.
However, in a category on NSArray, super's implementation is NSObject,
which is not what you want. This is a problem with categories, in that
it's impossible to call the original implementation of a method you
replace.

To get around this, either investigate using poseAsClass: or method
swizzling (http://www.cocoadev.com/index.pl?MethodSwizzling). Both of
these techniques allow you to call the old implementation in your
override.

Mike

Related mailsAuthorDate
mlvalueForKey and NSArray YL Jun 25, 02:15
mlRe: valueForKey and NSArray Michael Ash Jun 25, 19:40