这是我的代码,其中返回[arrayToFilter filteredArrayUsingPredicate:dupObjPredicate];花时间回应。
+ (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];
}
以下是[Facility removeDuplicatedObject:newObj]
的代码:
+ (void)removeDuplicatedObject:(NSManagedObject *)managedObject {
[[[RKManagedObjectStore defaultStore] mainQueueManagedObjectContext] deleteObject:managedObject];
[[[RKManagedObjectStore defaultStore] mainQueueManagedObjectContext] saveToPersistentStore:nil];
}