Objective C: Create arrays from first array based on value

Posted by Nic Hubbard on Stack Overflow See other posts from Stack Overflow or by Nic Hubbard
Published on 2010-05-04T16:39:08Z Indexed on 2010/05/04 16:48 UTC
Read the original article Hit count: 439

I have an array of strings that are comma separated such as:

Steve Jobs,12,CA
Fake Name,21,CA
Test Name,22,CA
Bill Gates,44,WA
Bill Nye,21,OR

I have those values in an NSScanner object so that I can loop through the values and get each comma seperated value using objectAtIndex.

So, what I would like to do, is group the array items into new arrays, based on a value, in this case, State. So, from those, I need to loop through, checking which state they are in, and push those into a new array, one array per state.

CA Array:
Steve Jobs,12,CA
Fake Name,21,CA
Test Name,22,CA

WA Array:
Bill Gates,44,WA

OR Array:
Bill Nye,21,OR

So in the end, I would have 3 new arrays, one for each state. Also, if there were additional states used in the first array, those should have new arrays created also.

Any help would be appreciated!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about iphone