유닛 테스트에서 나는 경계 조건을보고 있었고 테스트는 실패했습니다. 색인이 NSNotFound-1 (문서 당 최대 합법적 가치)까지 확장 될 때 색인 세트를 통해 열거하는 것으로 다시 추적했습니다.NSIndexSet enumerateIndexesUsingBlock의 버그입니까?
이 테스트 코드 사용 :
Index set with 5 entries: <NSIndexSet: 0x10057f890>[number of indexes: 5 (in 1 ranges), indexes: (9223372036854775802-9223372036854775806)]
NSNotFound is 9223372036854775807 and NSNotFound-1 is 9223372036854775806
- 9223372036854775802
- 9223372036854775803
- 9223372036854775804
- 9223372036854775805
The count is 4
내가 내 맥과 아이폰 OS 시뮬레이터에서이 작업을 시도합니다 (이외의 동일한 결과를 얻을 : 로그 출력에서
// Create an index set with NSNotFound-5, NSNotFound-4, NSNotFound-3,
// NSNotFound-2 and NSNotFound-1
NSIndexSet *testSet = [NSIndexSet indexSetWithIndexesInRange:
NSMakeRange(NSNotFound - 5, 5)];
NSLog(@"Index set with %lu entries: %@", (unsigned long) testSet.count, testSet);
NSLog(@"NSNotFound is %lu and NSNotFound-1 is %lu", NSNotFound, NSNotFound - 1);
__block int count = 0;
[testSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) {
NSLog(@"- %lu", (unsigned long) idx);
++count;
}];
NSLog(@"The count is %d", count);
를 내가 얻을 32 비트 또는 64 비트에 따라 NSNotFound의 실제 값).
이렇게하면 설명서를 잘못 읽었을 가능성이 있습니다. 내가 잘못했거나 애플 버그인가?
재미있는 질문입니다. +1 – trojanfoe
사실 그것은'enumerateIndexesWithOptions'에서 버그처럼 보입니다. –
'NSNotFound - 6'에서 범위를 시작하고 (길이 5를 유지하면) 작동합니까? –