How to count duplicates values in NSArray?

后端 未结 3 1227
情书的邮戳
情书的邮戳 2021-02-02 03:08

Value of my NSArray includes the duplicates. I find the duplicates but now how can I find the no. they repeat?

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-02 03:54

    You can try something like this

    __block NSInteger elementCount = 0;
    NSArray *array;
    
    [<#NSArray yourArray#> indexesOfObjectsPassingTest:^(id obj, NSUInteger idx, BOOL *stop){
        if (obj == <#yourObject#>) {
            elementCount++;
            return YES;
        }
        return NO;
    }];
    

    Let me know if that works for you

提交回复
热议问题