我有一个包含 10 个项目的数组。当我为 9 号元素和 10 号元素调用“ IndexOfObject
”时,Xcode 返回异常:“ NSRangeException
”
原因:'_[_NSCFArray objectAtIndex:] index:2147483647 超出界限(10)'。
从以前的NSLog
中,我看到这两个元素存在于数组中但indexOfObject
没有找到它们。为什么?
我的代码是:
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);