Is this an error in NSIndexSet enumerateIndexesUsingBlock?

In my unit testing, I looked at some boundary conditions and my tests did not work. I tracked it down to listing through an index, when its indexes extend all the way to NSNotFound-1 (maximum legal value for documentation).

Using this test code:

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

In the output log I get:

 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 

I tried this on my Mac and on the iOS simulator and got the same results (except for the actual NSNotFound values, depending on 32-bit or 64-bit).

It made me think, maybe I was reading the documentation incorrectly. Am I doing something wrong or is this an Apple error?

+6
source share
2 answers

Well, it looks like I have confirmation that it was / was a mistake. I turned on the bug report and heard from Apple that it was fixed in the latest release of OS X Yosemite Developer Preview and Xcode Preview. I downloaded it and it seems to have worked properly from the documentation.

I suspect that they had to change one line of code, so they asked if they would fix current or previous versions of Xcode, but I did not hear, and I did not hold my breath.

0
source

It's not a mistake. The value you set does not match the values. "The NSIndexSet class is an immutable collection of unique unsigned integers known as indexes because of how they are used. This collection is called an index. Indexes must be in the range 0 .. NSNotFound - 1." Here is the link !

0
source

Source: https://habr.com/ru/post/969436/


All Articles