gpt4 book ai didi

ios - 这是 NSIndexSet enumerateIndexesUsingBlock 中的错误吗?

转载 作者:可可西里 更新时间:2023-11-01 04:02:03 25 4
gpt4 key购买 nike

在我的单元测试中,我查看了一些边界条件,但我的测试一直失败。当它的索引一直延伸到 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 位)。

这让我觉得也许我读错了文档。我做错了什么或者这是 Apple 的错误吗?

最佳答案

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

关于ios - 这是 NSIndexSet enumerateIndexesUsingBlock 中的错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23712904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com