How could I enumerate an NSArray containing objects of multiple types, to get all the indexes where an NSString is found, then be able to refer to each index in order by saying
You can get an NSIndexSet
of the location of objects that you define with indexesOfObjectsPassingTest:
. Like so:
-(void)findStrings{
NSArray *randomObjects = [NSArray arrayWithObjects:[NSNull null], @"String", [NSNull null], @"String", [NSNull null], nil];
NSIndexSet *stringLocations = [randomObjects indexesOfObjectsPassingTest:^(id obj, NSUInteger idx, BOOL *stop){
return [(NSObject *)obj isKindOfClass:[NSString class]];
}];
NSLog(@"strings %@",stringLocations);
// You can get an array of just the passing objects like so:
NSArray *passingObjects = [randomObjects objectsAtIndexes:stringLocations];
}