// 1 - Find the matching item index
NSIndexSet* indexes = [[self.orderItems allKeys] indexesOfObjectsPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
IODItem* key = obj;
return [searchItem.name isEqualToString:key.name] &&
searchItem.price == key.price;
}];
// 2 - Return first matching item
if ([indexes count] >= 1) {
IODItem* key = [[self.orderItems allKeys] objectAtIndex:[indexes firstIndex]];
return key;
}
In this code I am checking through all the keys in the dictionary and comparing that with a search item.
When does this dictionary have multiple keys that have the same search item?
What I know for keys is that they are unique but this code is maintaining an index set for all the occurrences of the key that match to a particular search item.