Re: @distinctUnionOfObjects changes the order of objects?
Re: @distinctUnionOfObjects changes the order of objects?
- Subject: Re: @distinctUnionOfObjects changes the order of objects?
- From: Scott Anguish <email@hidden>
- Date: Tue, 21 Dec 2004 04:19:08 -0500
On Dec 20, 2004, at 5:03 PM, Harilaos Skiadas wrote:
Hi all,
I have the following relatively simple problem. I
have an NSArray that has two entries. Each entry is a
dictionary with two keys, @"ProgramCode" and
@"ProgramName". Actually it has more keys, but let's
not worry about them. The values of both keys are
NSStrings. What I want is, given a string aCode, much
aCode among the @"ProgramCode" key in the matrix, and
return the corresponding value of the key
@"programName". In my case in particular, lets say
that the first entry of the array has
ProgramCode="MCLY" and programName="Macaulay 2", while
the second entry has ProgramCode="PARI" and
programName="PARI/GP". What I thought should work was:
NSArray *codeList = [myArray
valueForKeyPath:@"@distinctUnionOfObjects.ProgramCode"];
unsigned int indexOfCode = [codeList
indexOfObject:aCode];
NSString *aProgramName = [[myArray
objectAtIndex:index] valueForKey:@"ProgramName"];
you misunderstand what @distinctUnionOfObjects gives you
it'll give you an array of uniqued values in ProgramCode, and you
can't guarantee the order to be preserved
you could keep a separate NSDictionary that contains the ProgramCode
string as the key, and the object in the array as the value. then you
could do the lookup in two stages (look up ProgramCode in the
dictionary, and then get ProgramName from the value returned
_______________________________________________
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