我正在尝试计算数组中重复对象的数量。当我将数组传递给我的 NSCountedSet 函数时,它没有对象。从我看到的示例中,通常将 NSArray 传递给 NSCountedSet,而我传递的是 NSMutableArray。但是,我找不到任何说明不允许这样做的文档。
-(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(...)
}