Latest 1.0.5
Homepage https://github.com/lgw51/WGBatchComparator
License MIT
Platforms osx , ios , tvos , watchos
Authors

Efficient way to perform bulk INSERT/UPDATE/DELETE in CoreData.

Have a look at Implementing Find-or-Create Efficiently in the "Core Data Programming Guide".

Another usage:

Before:

    NSArray *array1 = @[@"1",@"4",@"6"];
    NSArray *array2 = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
    NSMutableArray *result = [NSMutableArray array];
    for (NSString *obj1 in array1) {
        for (NSString *obj2 in array2) {
            if ([obj1 isEqualToString:obj2]) {
                [result addObject:obj1]; //or [result addObject:obj2];
            }
        }
    }

After:

    NSArray *array1 = @[@"1",@"4",@"6"];
    NSArray *array2 = @[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9"];
    NSMutableArray *result = [NSMutableArray array];

    //array1 and array2 must be in ascending order
    array1 = [array1 sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return [obj1 compare:obj2];
    }];
    array2 = [array2 sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
        return [obj1 compare:obj2];
    }];
    NSComparator comparator = [WGBatchComparator createCompareWithLeftValueKeyPaths:@[@"self"] rightValueKeyPaths:@[@"self"]]; //if UIView object, like @"layer.frame"
    [WGBatchComparator sourceEnumerator:array1.objectEnumerator desEnumerator:array2.objectEnumerator compare:comparator existOnDes:^(id sourceObj, id desObj) {
        [result addObject:sourceObj];
    } notExistOnDes:^(id sourceObj) {

    }];

Latest podspec

{
    "name": "WGBatchComparator",
    "version": "1.0.5",
    "summary": "Compare two array.",
    "description": "Efficient query whether a group of objects exist in another group of objects.nExample:nfor (NSManagedObject *managedObject in array) { //count = 1000n  //find in CoreData.n}",
    "homepage": "https://github.com/lgw51/WGBatchComparator",
    "license": "MIT",
    "authors": {
        "7owen": "[email protected]"
    },
    "source": {
        "git": "https://github.com/lgw51/WGBatchComparator.git",
        "tag": "1.0.5"
    },
    "source_files": "*.{h,m}",
    "platforms": {
        "osx": null,
        "ios": null,
        "tvos": null,
        "watchos": null
    }
}

Pin It on Pinterest

Share This