how to remove duplicate value in NSMutableArray

前端 未结 6 1398
离开以前
离开以前 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

    You can use NSSET but if you it is only used when order doesn't matter if order matter then go for this approach.I have used it and it give perfect answer. in Place of NSmutableArray array put your NSmutableArray which contains duplicate Value.

    NSArray *copy = [NSmutableArray copy];
    
    NSInteger index = [copy count] - 1;
    
    for (id object in [copy reverseObjectEnumerator])
     {
    
     if ([NSmutableArray indexOfObject:object inRange:NSMakeRange(0, index)] != NSNotFound)
    
     {
            [NSmutableArray removeObjectAtIndex:index];
    
     }
    
        index--;
    }
    
    [copy release];
    

提交回复
热议问题