Searches an array for a value using a binary search algorithm.
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+Beta
- tvOS 9.0+
- watchOS 2.0+
- Core Foundation
An array, sorted from least to greatest according to the
The range within
theto search. The range must not exceed the bounds of
the. The range may be empty (length
The value for which to find a match in
value, or any other value in
the, is not understood by the
comparatorcallback, the behavior is undefined.
The function with the comparator function type signature that is used in the binary search operation to compare values in
thewith the given value. If there are values in the range that the
comparatorfunction does not expect or cannot properly compare, the behavior is undefined.
A pointer-sized program-defined value, which is passed as the third argument to the
comparatorfunction, but is otherwise unused by this function. If the context is not what is expected by the
comparatorfunction, the behavior is undefined.
The return value is one of the following:
The index of a value that matched, if the target value matches one or more in the range.
Greater than or equal to the end point of the range, if the value is greater than all the values in the range.
The index of the value greater than the target value, if the value lies between two of (or less than all of) the values in the range.