更新时间:2023-02-10 20:48:58
您的代码与您提供的示例数据一起按预期工作:
Your code does work as expected with the example data you gave:
NSArray *_timesArray = @[@1, @23, @57, @59, @120];
NSTimeInterval currentTime = 109;
NSInteger playerTime=currentTime;
NSUInteger index = [_timesArray indexOfObject:@(playerTime)
inSortedRange:NSMakeRange(0, _timesArray.count-1)
options:NSBinarySearchingFirstEqual | NSBinarySearchingInsertionIndex
usingComparator:^(id a, id b) {
return [a compare:b];
}];
NSLog(@"Index: %lu", (unsigned long)index);
输出:
Index: 4
检查您的输入.很可能它们不是您认为的那样.
Check your inputs. Likely they are not what you think they are.