NSMutableArray removeLastObject exception

As per NSMutableArray documentation :

removeLastObjectcalls NSRangeExceptionif there are no objects in the array.

For some reason, I seem to be able to call this method in an empty array, and no exception is thrown.

Here's a test case:

- (void)testNSMutableArray
{
    NSMutableArray* arr = [[NSMutableArray alloc] init];
    STAssertTrue([arr count] == 0, @"Array count should be 0");
    STAssertThrows([arr removeLastObject], @"Should throw NSRangeException");
}

This test case does not work on the last line for me with the message:

[arr removeLastObject] raised (null). Must throw an NSRangeException

Am I confused here? Incorrect documentation?

+5
source share
2 answers

Looking at the assembly, this behavior seems to have changed in Lion. Here's the part of the implementation [__NSArrayM removeLastObject](which is the actual implementation that you are calling):

0x3494975a:  movs   r0, #7
0x3494975c:  bl     0x3490c26c                ; _CFExecutableLinkedOnOrAfter
0x34949760:  cbz    r0, 0x3494977c            ; -[__NSArrayM removeLastObject] + 60

CFExecutableLinkedOnOrAfter 7; 1 ( ), , . 0, .

CFExecutableLinkedOnOrAfter - , , , Mac OS X. snooping , 7 10.7.

, Lion , . !

+5

, (, , ) . NSRangeException , i, . [arr removeLastObject], , iOS , ,

+1

All Articles