Reputation: 6039
Take the code below:
NSPredicate *predicateSource = [NSPredicate predicateWithFormat:@"SELF = %d",5];
NSArray *filteredArraySource = [[[self.myArray copy]autorelease] filteredArrayUsingPredicate:predicateSource];
myArray
(NSMutableArray
) contains 100 integers (numbers 1-100 in random order). What I'd like to do is somehow find out which index contains the number 5
without looping through each object in the array. The above code only extracts the object and places it into an array.
Any suggestions?
Upvotes: 4
Views: 160
Reputation: 726519
You can use indexOfObjectPassingTest:
. If you need to use NSPredicate
, call your predicate's evaluateWithObject:
inside the block; otherwise, simply check the object's integer value to be 5
.
Upvotes: 1