iOS 数组统计重复字段和次数

    NSCountedSet *set = [[NSCountedSet alloc] initWithArray:names];
    for (id item in set)
    {
        NSLog(@"Name=%@, Count=%lu", item, (unsigned long)[set countForObject:item]);
    }
结果:Name=0, Count=2
           Name=1, Count=2
           Name=2, Count=1

你可能感兴趣的:(iOS 数组统计重复字段和次数)