• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: valueForKey and NSArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >valueForKey and NSArray (From: "YL" <email@hidden>)

  • Prev by Date: file filter popup at *top* of save panel
  • Next by Date: cascading spotlight importer
  • Previous by thread: valueForKey and NSArray
  • Next by thread: Clickable NSImageCell in NSMatrix
  • Index(es):
    • Date
    • Thread