ios - Remove (not exact) duplicates of NSDictionaries from array -
i have nsmutablearray of many nsdictionaries contain keys "title". in cases there duplicates of dictionaries same "title" differences in other keys. how can remove dictionaries have same "title" key , leave 1 in array?
thanks
sort array using nssortdescriptor
on key path 'title'. next, loop on array , build new array:
nsstring *lasttitle = nil; nsmutablearray *result = [nsmutablearray array]; (nsdictionary *d in array) { nsstring *testtitle = [d objectforkey:@"title"]; if (![testtitle isequaltostring:lasttitle]) { [result addobject:d]; lasttitle = testtitle; } }
now result
contains filtered list.
it's important sort array
first algorithm work.
Comments
Post a Comment