I have an NSArray and a lot of the values have the same values (i know this isn’t the best way to do an array). How can i search for a string within the array and have it return me an array of indexes. For example if i wanted to search the array for “DJ Ez”, how can i have it so it returns all the indexes where the index is equal to that string? So far i have tried this:
do {
isTheObjectThere = [array containsObject: @"DJ Ez"];
if(isTheObjectThere == true){
indexOfTheObject = [array indexOfObject: @"DJ Ez"];
[arrayOfIndexes addObject:[NSNumber numberWithInt:indexOfTheObject]];
[array removeObjectAtIndex:indexOfTheObject];
NSLog(@"%@", [indexesForAll objectAtIndex:intCtrl]);
hasFinished = false;
}else{
hasFinished = true;
}
intCtrl++;
} while (hasFinished == false);
However this doesn’t work as when it deletes the item it messes up all the indexes for the next search. What do i do?
How about something like this:
That should return all of the matching indexes as an NSIndexSet, which allows you do check if specific indexes matched, or you can get the count and loop through the matching indexes however you wish.