• 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
valueForKey and NSArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

valueForKey and NSArray


  • Subject: valueForKey and NSArray
  • From: "YL" <email@hidden>
  • Date: Sat, 24 Jun 2006 18:15:20 -0600

Hi list,
We know given a dictionary like
foo = {
            a = ...
            b = ( {result = ok; date = d1; }, { result = good; date = d6;}, { result = bad; date = d3;});
            ...
          }
[foo valueForKeyPath:@"b.result"] will return an array (ok,good,bad)

---------------------------------
I'm trying to make

[dict valueForKeyPath: @"b.1.date"] returning  'd6' and
[dict valueForKeyPath: @"b.0.result"] returning  'ok'

It seems to me that all i need to do is a category method
- (id) valueForKey:(NSString *)aKey;
for NSArray that do the same thing as usual except when aKey is representing an integer:
when aKey represents an integer, the method returns the object at the index of that integer
if possible, otherwise nil.

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

Any ideas?


 _______________________________________________
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

  • Follow-Ups:
    • Re: valueForKey and NSArray
      • From: "Michael Ash" <email@hidden>
  • Prev by Date: Re: objc_msgSend_stret Intel crashes
  • Next by Date: Re: top level objects and NSWindowController
  • Previous by thread: Removing all objects in NSTreeController
  • Next by thread: Re: valueForKey and NSArray
  • Index(es):
    • Date
    • Thread