title: Binary searching through an array with indexOfObject:inSortedRange:options:usingComparator:
body: <p>I don't understand the array method <code>indexOfObject:inSortedRange:options:usingComparator:</code></p>
  
  <p>More specifically, the <code>indexOfObject</code> property.</p>
  
  <p>According to the docs the value passed in should be <code>An object for which to search in the array.</code>  But this makes no sense.. if i already had a reference to the object, why would i be searching for it in an array?  Does it mean the object type?</p>
  
  <p>I have an array of objects, and all I have is a property of those objects.  ie.  I have an array of cars and I need to find the car object when I have the car ID of 12345.</p>
  
  <p>What would I pass into the the method for the <code>indexOfObject</code> property?  here is what I'm trying</p>
  
  <pre><code>   MyCarObject *searchObject;
     NSUInteger findIndex = [sortedArray indexOfObject:searchObject
                                         inSortedRange:searchRange
                                               options:NSBinarySearchingFirstEqual
                                       usingComparator:^(id obj1, id obj2)
                                {
                                  return [obj1 compare:obj2];
                                }];
  </code></pre>
  
  <p>but this clearly isn't going to get an object based on the ID.. it appears like its going to give me the index of the property i already have a reference to, which seems pointless....</p>
  
  <p>If this isn't the correct method, then what should I be using?  I need to use a binary search on array of objects and pull out the reference to that object.  And all I have is a property to compare.</p>