FROM : Harilaos Skiadas
DATE : Mon Dec 20 23:03:21 2004
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"];
What happens when I try to debug this, is that
codeList contains the codes in the reverse order than
the order they appeared in the array, i.e. PARI comes
first, and MCLY second. Of course the result of this
is that the index information I get out of this is
useless.
Is this something to be expected? I can't rely on
@distinctUnionOfObjects not to mess up the order of
things?
Is there a better way to accomplish what I am trying
to do, without actually writing my own loop that goes
through the array entries?
Haris
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
DATE : Mon Dec 20 23:03:21 2004
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"];
What happens when I try to debug this, is that
codeList contains the codes in the reverse order than
the order they appeared in the array, i.e. PARI comes
first, and MCLY second. Of course the result of this
is that the index information I get out of this is
useless.
Is this something to be expected? I can't rely on
@distinctUnionOfObjects not to mess up the order of
things?
Is there a better way to accomplish what I am trying
to do, without actually writing my own loop that goes
through the array entries?
Haris
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com
| Related mails | Author | Date |
|---|---|---|
| Harilaos Skiadas | Dec 20, 23:03 | |
| Scott Anguish | Dec 21, 10:19 | |
| Harilaos Skiadas | Dec 21, 20:19 |






Cocoa mail archive

