I don't understand the array method indexOfObject:inSortedRange:options:usingComparator:
More specifically, the indexOfObject property.
According to the docs the value passed in should be An object for which to search in the array. 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?
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.
What would I pass into the the method for the indexOfObject property? here is what I'm trying
MyCarObject *searchObject;
NSUInteger findIndex = [sortedArray indexOfObject:searchObject
inSortedRange:searchRange
options:NSBinarySearchingFirstEqual
usingComparator:^(id obj1, id obj2)
{
return [obj1 compare:obj2];
}];
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....
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.