Contents

differenceFromArray:

Compares two arrays to create a difference object that represents the changes between them.

Declaration

- (NSOrderedCollectionDifference<id> *) differenceFromArray:(NSArray<id> *) other;

Discussion

The difference method creates the difference object by comparing objects within the arrays with the isEqual: method.

The following example computes the difference between two arrays:

NSArray *original = @[@"1", @"2"];
NSArray *modified = @[@"1", @"2", @"3"];

NSOrderedCollectionDifference *diff = [modified differenceFromArray:original];
// diff.hasChanges == TRUE
// diff.insertions.count == 1
// diff.removals.count == 0

See Also

Comparing with Another Array