This is my code in which return [arrayToFilter filteredArrayUsingPredicate:dupObjPredicate]; is taking time to respond.
+ (NSArray *)removeDuplicatesInArray:(NSArray*)arrayToFilter{
NSMutableSet *dupList = [NSMutableSet set];
NSPredicate *dupObjPredicate = [NSPredicate predicateWithBlock: ^BOOL(id obj, NSDictionary *bind) {
Facility *newObj = (Facility*)obj;
BOOL hasObject = [dupList containsObject:newObj.tsFacilityId];
if (!hasObject) {
if (![dupList containsObject:newObj.tsFacilityLocalId]) {
[dupList addObject:newObj.tsFacilityId ? newObj.tsFacilityId : newObj.tsFacilityLocalId];
}
} else {
[Facility removeDuplicatedObject:newObj];
}
return !hasObject;
}];
return [arrayToFilter filteredArrayUsingPredicate:dupObjPredicate];
}
Below is the code of [Facility removeDuplicatedObject:newObj]
:
+ (void)removeDuplicatedObject:(NSManagedObject *)managedObject {
[[[RKManagedObjectStore defaultStore] mainQueueManagedObjectContext] deleteObject:managedObject];
[[[RKManagedObjectStore defaultStore] mainQueueManagedObjectContext] saveToPersistentStore:nil];
}