Reputation: 517
I have NSMutableArray
with data like: "John","Phillip","John","Andrea". I have also a String "John". I need to find that string in NSMutableArray
and define which index is to show other data in other arrays. In my case index is 0 and 2.
This show only first
NSInteger index = [array indexOfObject:String];
Upvotes: 1
Views: 172
Reputation: 726559
NSArray
provides a method that produces a set of indexes based on a condition that you supply:
NSIndexSet *allPositions = [array indexesOfObjectsPassingTest:
^BOOL (id str, NSUInteger i, BOOL *stop) {
return [str isEqualToString:String];
}];
This produces NSIndexSet
which has all indexes of interest - in your case, it would have 0 and 2.
Upvotes: 4