ios - how to remove duplicates from array of dictionary for a specific key -


{     distance = "0.03159804520191554";     rid = 374824705969;     uuid = "1838346268_374823983610_2016-08-08t07:32:08.679gmt"; }, {      rid = 374824705969;     uuid = "1838346268_374823983610_2016-08-08t07:32:08.679gmt"; }, {     rid = 374824706065;     uuid = "1838346268_374823983610_2016-08-08t07:32:22.680gmt"; }   

this got array of dictionaries. want remove duplicates rid=374824705969 without using loops.can 1 me. in advance.

try these one:

nsarray *array = @[     @{         @"rid" : @374824705969,         @"uuid" : @"1838346268_374823983610_2016-08-08t07:32:08.679gmt"     },     @{         @"rid" : @374824705969,         @"uuid" : @"1838346268_374823983610_2016-08-08t07:32:08.679gmt"     },     @{         @"rid" : @374824706065,         @"uuid" : @"1838346268_374823983610_2016-08-08t07:32:22.680gmt"     }];       nsmutableset *keys = [nsmutableset new];     nsmutablearray *result = [nsmutablearray new];      (nsdictionary *data in array) {         nsstring *key = data[@"rid"];         if ([keys containsobject:key]) {             continue;         }          [keys addobject:key];         [result addobject:data];     }  nslog(@"%@", result); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -