ios - Remove duplicates from NSMutableArray of NSDictionary depending on value of key -
i have nsmutablearray
of, say, 10 nsmutablearrays
. each of these nsmutablearrays
contains different number of nsdictionary
objects have made model class. data api response. first time make api call, response whole data. on, when api call made, returns data modified.
when new data api response, contains data in array of dictionaries slight modifications.
model class's structure below:
subcategory.h
@interface subcategory : mtlmodel <mtljsonserializing> @property (nonatomic, retain) nsstring *subcategoryid; @property (nonatomic, retain) nsstring *subcategoryname; @property (nonatomic, retain) nsstring *status; @end
json object returned this:
{ "sub_category" = ( { id = 55ed48123; name = "sub category 1"; status = 1; }, { id = 55ed47ed3; name = "sub category 2"; status = 1; } ); }
the 'id' field of new data same. 'name' , 'status' fields different. want replace data in nsmutablearray
of nsdictionary
objects new data retains order of objects in array. how can this?
1: use nspredicate
create criteria duplicate condition.
2: use filteredarrayusingpredicate
array of duplicated objects.
3: remove 1 object duplicated array.
4: use removeobjectsinarray
remove list of objects in duplicated array original array.
Comments
Post a Comment