title: How to search in a plist to retrieve a value for a specific key
body: <p>I am using a plist to store the country data for my app's users. So I have this <code>&lt;dict&gt;</code> list that holds several <strong>countries</strong>. For each country there are several <strong>provinces</strong>. For each region there are <strong>regions</strong>. And each region holds many <strong>cities</strong>.</p>
  
  <p>So my list looks like the following:</p>
  
  <pre><code>&lt;dict&gt;
      &lt;key&gt;Country&lt;/key&gt;
      &lt;array&gt;
          &lt;dict&gt;
              &lt;key&gt;ISO&lt;/key&gt;
              &lt;string&gt;ES&lt;/string&gt;
              &lt;key&gt;Value&lt;/key&gt;
              &lt;string&gt;Spain&lt;/string&gt;
              &lt;key&gt;Children&lt;/key&gt;
              &lt;array&gt;
                  &lt;dict&gt;
                      &lt;key&gt;ISO&lt;/key&gt;
                      &lt;string&gt;AL&lt;/string&gt;
                      &lt;key&gt;Value&lt;/key&gt;
                      &lt;string&gt;Andalucia&lt;/string&gt;
                      &lt;key&gt;Children&lt;/key&gt;
                      &lt;array&gt;
                          ...
                      &lt;/array&gt;
                  &lt;/dict&gt;
              &lt;/array&gt;
          &lt;/dict&gt;
      &lt;/array&gt;
  &lt;/dict&gt;
  </code></pre>
  
  <p>The most detailed node is the city which holds information as:</p>
  
  <pre><code>&lt;dict&gt;
      &lt;key&gt;ISO&lt;/key&gt;
      &lt;string&gt;03002&lt;/string&gt;
      &lt;key&gt;Value&lt;/key&gt;
      &lt;string&gt;ALICANTE&lt;/string&gt;
  &lt;/dict&gt;
  </code></pre>
  
  <p>In the database I then store <strong>03002</strong> which is the unique key for <strong>Alicante</strong> in this case. But in my GUI I obviously want to display Alicante and not the numeric representation.</p>
  
  <p><strong>So is there an easy way to search this plist file to find the matching Value for this ISO ?</strong></p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>At the moment I created this method. It does the trick, but I cannot really call it efficient coding. So please advise...</p>
  
  <pre><code>- (NSString *)getCityNameForKey: (NSString *)ISO {
      NSString *cityName = @"";
      NSArray *citySource = [[Locations getInstance] toDataSource];
  
      for (int i = 0; i &lt; [citySource count]; i++) {
          //Country
          NSDictionary *p_dictionary = [citySource objectAtIndex:i];
          NSArray *provinces = [p_dictionary objectForKey:@"Children"];
          if ([provinces count] &gt; 0) {
              //Province
              for (int j = 0; j &lt; [provinces count]; j++) {
                  NSDictionary *r_dictionary = [provinces objectAtIndex:j];
                  NSArray *regions = [r_dictionary objectForKey:@"Children"];
                  if ([regions count] &gt; 0) {
                      //City
                      for (int k = 0; k &lt; [regions count]; k++) {
                          NSDictionary *c_dictionary = [regions objectAtIndex:k];
                          NSArray *cities = [c_dictionary objectForKey:@"Children"];
                          if ([cities count] &gt; 0) {
                              for (int l = 0; l &lt; [cities count]; l++) {
                                  NSDictionary *result_dict = [cities objectAtIndex:l];
                                  if ([[result_dict objectForKey:@"ISO"] isEqualToString:ISO]) {
  
                                      index_country = i;
                                      index_province = j;
                                      index_region = k;
                                      index_city = l;                                    
  
                                      cityName = [result_dict objectForKey:@"Value"];
                                      return cityName;
                                      break;
                                  }
                              }
                          }
  
                      }
                  }
              }
          }
      }
      return cityName;
  }
  </code></pre>