What you're doing should work fine. For example
NSArray *a = [NSArray arrayWithObjects:@"Foo", @"Bar", @"Baz", nil];
NSLog(@"At index %i", [a indexOfObject:@"Bar"]);
Correctly logs "At index 1" for me. Two possible foibles:
indexOfObject
sends isEqual
messages to do the comparison - you've not replaced this method in a category?
- Make sure you're testing against
NSNotFound
for failure to locate, and not (say) 0.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…