Baerdon
Baerdon

Reputation: 145

NSMutable array counting objects of specific type

I have NSMutableArray full of objects of two different types. I need to find out number of objects of certain type. Does exist some function like count to count objects of specific type, or I have to iterate through array and count them manually?

Thank you.

Upvotes: 0

Views: 47

Answers (1)

Sadiq Jaffer
Sadiq Jaffer

Reputation: 500

Try this

NSInteger *countTypeA;
NSInteger *countTypeB;
for (id object in array) {
    if ([object isKindOfClass:[firstType class]]) {
        countTypeA++;
    } else if ([object isKindOfClass:[secondType class]]){
        countTypeB++;
    }
}

Upvotes: 1

Related Questions