title: ios NSPredicate to find nearest value in NSDictionary
body: <p>I have an <strong>array of dictionaries</strong> like this:</p>
  
  <pre><code>(
  { key = 1, value = 40},
  { key = 4, value = 50},
  { key = 8, value = 60}
  }
  </code></pre>
  
  <p>These are like this, 
  <code>for &gt;=1</code> <em>item cost is 40</em>,
  <code>for &gt;=4</code> <em>item cost is 50</em> and like wise.</p>
  
  <p>I would like to get the value for 5, which in this case is 50.</p>
  
  <p>The piece of code I have tried is:</p>
  
  <pre><code>NSMutableArray *wallpaperPriceArray = [[NSMutableArray alloc]init]; // Assuming this has all the dictionary values 
  
  float wallpaperPriceValue = 0;
  
  int itemNumber = 0;
  
  for (int i = 0; i&lt;wallpaperPriceArray.count; i++) {
  
  int check = 0;
  
  if(itemNumber &gt;= [[wallpaperPriceArray objectAtIndex:i] intValue])
  {
      wallpaperPriceValue = [[[wallpaperPriceArray objectAtIndex:i] objectForKey:@"value"] floatValue];
      check++;
  }
  
  if(i + 1 &lt;= wallpaperPriceArray.count)
  {
      if(itemNumber &gt;= [[wallpaperPriceArray objectAtIndex:i+1] intValue] &amp;&amp; itemNumber &lt; [[wallpaperPriceArray objectAtIndex:i+1] intValue])
      {
          wallpaperPriceValue = [[[wallpaperPriceArray objectAtIndex:i+1] objectForKey:@"value"] floatValue];
          check++;
  
          if(check == 2)
          {
              break ;
          }
      }
  }
  
  if(i + 2 &lt;= wallpaperPriceArray.count)
  {
      if(itemNumber &gt;= [[wallpaperPriceArray objectAtIndex:i+2] intValue] &amp;&amp; itemNumber &lt; [[wallpaperPriceArray objectAtIndex:i+2] intValue])
      {
          wallpaperPriceValue = [[[wallpaperPriceArray objectAtIndex:i+2] objectForKey:@"value"] floatValue];
          check++;
  
          if(check == 2)
          {
              break ;
          }
      }
  }
  </code></pre>