I am running a for-in loop over an NSMutableArray
. There are instances of Class A
in the array also out of those some are actually instances of its subclass B
.
So If I only want members of subclass B
, I am checking the class of each object I get in an if
condition inside the loop body.
Is it possible that instead of writing something like this,
for(A* obj in collection){
if([obj isKindOfClass:[B class]]){
//take some action.
}
}
I can do something like this?
for(B* obj in collection){
//take some action.
}
Will I get the same result?