I accessed the Data from sqlite file as NSMutableArray[model_Array] in which I have duplicates info [two/three] so i wanna delete that, I tried to assign the MutableArray to another NSMutableArray[allItems] by two different idea given below
AppDelegate *readTheDatabase = (AppDelegate *)[[UIApplication sharedApplication] delegate];
allItems = [[NSMutableArray alloc] initWithArray:readTheDatabase.model_Array];
NSSet *uniqueItems;
uniqueItems = [NSSet setWithArray:allItems];
or
NSMutableArray *uniqueItems = [NSMutableArray array];
for (id item in allItems)
if (![uniqueItems containsObject:item])
[uniqueItems addObject:item];
but it is unable to delete the duplicate data. please anyone help and suggest me to overcome this problem. Thanks in advance.
Your objects within the array are obviously not returning true for the
isEqual:method.What kind of object does the array contain?
I assume it’s some custom model class that represents the data in the database.
You should look up the documentation for
NSObjectand theisEqual:andhash:methods.You will learn how to express when two objects are equal, which is how
NSArrayandNSSetetc determine whether objects are already contained within the collection.