“filteredArrayUsingPredicate”花时间回应

时间:2018-01-23 06:19:03

标签: ios objective-c uitableview core-data restkit

这是我的代码,其中返回[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];
}

0 个答案:

没有答案