how to remove duplicate value in NSMutableArray

前端 未结 6 1348
离开以前
离开以前 2021-01-24 22:32

i\'m scanning wifi info using NSMutableArray, but there are few duplicate values appear, so i try to use following code but still getting the duplicate values,

         


        
6条回答
  •  不知归路
    2021-01-24 23:01

    maybe you can try the NSArray category.

    #import 
    
    @interface NSArray(filterRepeat)
    -(NSArray *)filterRepeat;
    
    @end
    
    
    #import "NSArray+repeat.h"
    @implementation NSArray(filterRepeat)
    -(NSArray *)filterRepeat
    {
        NSMutableArray * resultArray =[NSMutableArray array];
        [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            if (![resultArray containsObject: obj]) {
                [resultArray addObject: obj];
            }
        }];
        return resultArray;
    }
    @end
    

提交回复
热议问题