Remove duplicate from nsmutablearray containing nsdictionary

后端 未结 2 1136
余生分开走
余生分开走 2021-01-15 04:55

I want to remove duplicates from nsmutablearray.

Array Structure :-

(
    {
        \"act_end_date\" = \"\";
        \"act_entry_date\"          


        
2条回答
  •  被撕碎了的回忆
    2021-01-15 05:27

        NSMutableSet *keysSet = [[NSMutableSet alloc] init];
        NSMutableArray *filteredArray = [[NSMutableArray alloc]init];
        for (NSDictionary *msg in germanMakes) {
        NSString *key = [NSString stringWithFormat:@"%@", msg[@"act_id"]];
        if (![keysSet containsObject:key]) {
            [filteredArray addObject:msg];
            [keysSet addObject:key];
        }
        }
        NSLog(@"filteredResults %@ keyset%@",filteredArray , keysSet);
    

    germanMakes is your initial array, keysSet contains unique act_id (e.g. 1,2,3,4..), filteredArray is your array filtered by act_id. Keep in mind this does not get sorted ascending, but that part will be easy.

提交回复
热议问题