Search through an array of dictionaries with multiple criteria

I have many NSDictioanries in NSArray. Since there are about 1300 of them, and I need to search for them according to the following criteria:

1. Name
2. DOB
3. Type
4. Grade
5. Condition
6. PUP 
7. Unit Number

Here is an example of such a dictionary:

<Unit>
<UnitNumber>20110501100507134</UnitNumber>
<Name>01'' 2ply Mat</Name>
<DOB>3/24/2011 12:00:00 AM</DOB>
<Type>2ply Mat</Type>
<Grade>Cull</Grade>
<Condition />
<Depth>01</Depth>
<Width>01</Width>
<Length>01</Length>
<PUP>Cable</PUP>
<Finishing />
</Unit>

Right now I’m thinking about iterating over an array, looking for the first criterion, then again looping through the filtered array and looking for the second criterion, and so on .... But this is 7 for loops of at least 1300 dictionaries.

What are my alternatives? Thank.

UPDATE: Okay, so for each of the criteria listed above, I will have a text box and the user will specify the criteria there, and then click the search button ... (if that becomes more clear)

Also, it is for iPhone / iPad

+3
source share
3 answers
+7

@Robin , , .

+1

, , iPhone/iPod. , , , , .

array

matt

bob

mrlol

/array

Then use the index number from this array and extract the dictionary. This may not be the clearest explanation, please comment if you have questions.

Edit: to the previous answer, I don’t think he was asking about how to compare the data, I think he wanted to find a way to find the data, so I don’t think that NSPredicate was what he was looking for.

0
source

All Articles