Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IndexOfObject return 2147483647

I have an array with 10 items. When I call "IndexOfObject" for the elements number 9 and the element number 10 Xcode return an exception: "NSRangeException"

reason: '_[_NSCFArray objectAtIndex:] index:2147483647 beyond bounds(10)'.

From a previous NSLog, I saw that the two elements exist in the array but indexOfObject not find them. Why?

My code is:

    NSDictionary * headConfig =[avatarDictionaryToSave objectForKey:@"head_dictionary"];
    NSString * headImage =[headConfig objectForKey:@"layer_key"];
    NSString * pathFace =[[NSBundle mainBundle]pathForResource:@"Face" ofType:@"plist"];
    NSLog(@"%@", headImage);

    NSArray *arrayFace =[NSArray arrayWithContentsOfFile:pathFace];
    NSLog(@"the  elements are: %@", arrayFace);//here headImage is present
    int index =[arrayFace indexOfObject:headImage];
    NSLog(@"the index is %d", index);
like image 254
Adriana Carelli Avatar asked Jun 07 '12 10:06

Adriana Carelli


1 Answers

indexOfObject: returns NSNotFound when the object is not present in the array. NSNotFound is defined as NSIntegerMax (== 2147483647 on iOS 32 bit).

So it seems that the object you are looking for is just not there.

like image 180
Nikolai Ruhe Avatar answered Oct 13 '22 16:10

Nikolai Ruhe