6

在我的单元测试中,我查看了一些边界条件,但我的测试一直失败。当它的索引一直延伸到 NSNotFound-1 (每个文档的最大合法值)时,我将其追溯到通过索引集进行枚举。

使用此测试代码:

// 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 );

在日志输出中我得到:

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  

我在我的 Mac 和 iOS 模拟器上尝试了这个并得到了相同的结果(除了 NSNotFound 的实际值,取决于 32 位或 64 位)。

这让我觉得也许我读错了文档。我做错了什么还是这是苹果的错误?

4

2 回答 2

0

这不是一个错误。您设置的值超出了有效值。“NSIndexSet 类表示唯一无符号整数的不可变集合,由于它们的使用方式而称为索引。这个集合称为索引集。索引必须在 0 .. NSNotFound - 1 范围内。” 这是链接

于 2014-06-09T03:54:07.233 回答
0

好吧,看起来我已经确认它是/曾经是一个错误。我提交了一份错误报告,并从 Apple 那里听说它已在最新的 OS X Yosemite Developer Preview 和 Xcode Preview 中得到修复。我下载了它,它似乎按文档中的预期工作。

我怀疑他们必须更改一行代码,所以问他们是否会修补当前或以前版本的 Xcode,但我没有听说过,我也没有屏住呼吸。

于 2014-08-28T15:55:36.520 回答