Re: valueForKey and NSArray
Re: valueForKey and NSArray
- Subject: Re: valueForKey and NSArray
- From: "Michael Ash" <email@hidden>
- Date: Sun, 25 Jun 2006 13:40:46 -0400
On 6/24/06, YL <email@hidden> 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
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden