iOS, Core Data: set argument is not an NSSet error when counting an NSSet

3.2k views Asked by At

Such error happens sometimes when listing the same tableView, I mean sometimes yes and sometimes no. When I try to check retrieved NSSet for if he contains any objects:

if(coin.dublicates.count > 0)

I get error :

*** -[NSMutableSet unionSet:]: set argument is not an NSSet'

What would be the reason for such error? whole method listing:

if(period.regions.count == 0) {

    for(Nominal *nominal in period.nominals) {

        if(nominal.coins.count>0) {

            counter+=[[nominal.coins filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"listed==%@",[NSNumber numberWithBool:YES]]]count];
            for(Coin *coin in nominal.coins)
            {

                if(coin.dublicates.count > 0) {

                    counter+=coin.dublicates.count;
                }
            }
        }
    }
}

screenshot:

enter image description here

Thank you in advance.

1

There are 1 answers

2
Mark McCorkle On BEST ANSWER

Verify the NSSet is not nil before evaluating its count.

if (coin.dublicates) {
    // Do stuff
}