Tag Archives: gist

Binary Search NSArray

Though CFArray comes with binary search capability, NSArray does not – at least not within the iPhone SDK. The indexOfObject:inSortedRange:options:usingComparator: can’t be found. Plus the CFArrayBSearchValues doesn’t tell you whether the key actually is part of the list or not. That’s what the Java JDK does, so let’s implement some category methods -(NSInteger)binarySearch:(id)key; -(NSInteger)binarySearch:(id)key usingSelector:(SEL)comparator; […]