I have NSMutableArray with objects like this : “0,1,0,1,1,1,0,0”
And i need to get indexes of all objects with value “1”
I’m trying to get it with following code:
for (NSString *substr in activeItems){
if ([substr isEqualToString:@"1"]){
NSLog(@"%u",[activeItems indexOfObject:substr]);
}
}
But as it says in documentation method indexOfObject: ” returns – The lowest index whose corresponding array value is equal to anObject.”
Question: How i can get all indexes of array with value of “1” ?
You can use this method of
NSArray:(documentation here.)
And this is how you can get the indexes as the elements of an array (represented by
NSNumberobjects):and then
arraywill contain all the indexes of the matching objects wrapped inNSNumbers.