---
title: inverse()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/nsorderedcollectiondifference/inverse()
---

# inverse()

Calculate the difference between two objects in the reverse direction of comparison.

## Declaration

```swift
func inverse() -> Self
```

## Return Value

Return Value A copy of the receiver with all removals changed to insertions (and vice versa).

## Discussion

Discussion Applying a difference to an ordered collection and then applying the inverse difference results in the original ordered collection: NSArray *original = @[@"1", @"2"]; NSArray *modified = [original arrayByAddingObject:@"3"];

NSOrderedCollectionDifference *diff = [modified differenceFromArray:original];

NSArray *updated = [original arrayByApplyingDifference:diff]; // updated == [@"1", @"2", @"3"] == modified

NSOrderedCollectionDifference *inverse = [diff inverseDifference];

updated = [updated arrayByApplyingDifference:inverse]; // updated == [@"1", @"2"] == original
