iphonecocoaduplicatesnscountedset

NSCountedSet has no objects


I am trying to count the number duplicate objects that I have in an array. When I pass the array to my NSCountedSet function, it has no objects. From the examples I have seen, the usually pass NSArray to NSCountedSet where as I am passing an NSMutableArray. But, I can find no documentation that says that is not allowed.

-(void)GetDays
{
       ...
       BOOL goodDuplicates = NO;
       NSMutableArray *mostDaysAttended = [[NSMutableArray alloc] init];
       mostDaysAttended = [self gatherDays];
       goodDuplicates  = [self checkDuplicatesforIndex:mostDaysAttended];
       ...

{


-(BOOL)checkDuplicatesforIndex: (NSMutableArray *)mostDaysAttended
{


    NSCountedSet *set   = [[NSCountedSet alloc] initWithArray:mostDaysAttended];

    for (id item in set)  //<== at this point "set" has zero objects
    ...
    return(...)
}

Solution

  • This is the code after the "NSCountedSet" declaration and before the "for" loop.

      //INITIALIZE
      for( int g =0;g<=11;g++)
        indexCount[g]=0;
    

    Once I removed this loop and placed it at the beginning of the function before all of the other declarations, the code began working as expected. I am not sure why this would have affected the number of objects in the set, but it did.