<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSOrderedCollectionDifference",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSOrderedCollectionDifference"
  },
  "title" : "NSOrderedCollectionDifference"
}
-->

# NSOrderedCollectionDifference

An object representing the difference between two ordered collections.

```
class NSOrderedCollectionDifference
```

## Overview

Use [`differenceFromArray:`](/documentation/Foundation/NSArray/differenceFromArray:) or one of its variations to get an instance of [`NSOrderedCollectionDifference`](/documentation/Foundation/NSOrderedCollectionDifference), which represents the difference between two ordered collections.

For example, the following sample compares two arrays of strings to create a difference that represents the changes:

```objc
NSArray *original = @[@"Red", @"Green", @"Blue"];
NSArray *modified = @[@"Red", @"Blue", @"Green"];

NSOrderedCollectionDifference *diff = [original differenceFromArray:modified];

// diff.hasChanges == TRUE
// diff.insertions.count == 1
// diff.removals.count == 1
```

## Topics

### Accessing Changes

[`hasChanges`](/documentation/Foundation/NSOrderedCollectionDifference/hasChanges)

A Boolean value that indicates if the difference has changes.

[`insertions`](/documentation/Foundation/NSOrderedCollectionDifference/insertions)

A collection of insertion change objects.

[`removals`](/documentation/Foundation/NSOrderedCollectionDifference/removals)

A collection of removal change objects.

[`NSOrderedCollectionChange`](/documentation/Foundation/NSOrderedCollectionChange)

An object that represents an indexed change within an ordered collection.

[`NSCollectionChangeType`](/documentation/Foundation/NSCollectionChangeType)

The type of change represented in computing the difference of an ordered collection.

### Inverting a Difference Object

[`-  inverseDifference`](/documentation/Foundation/NSOrderedCollectionDifference/inverse())

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

### Creating a Collection Difference Object

[`-  initWithChanges:`](/documentation/Foundation/NSOrderedCollectionDifference/init(changes:))

Creates an ordered collection difference using an array of ordered collection changes.

[`-  initWithInsertIndexes:insertedObjects:removeIndexes:removedObjects:`](/documentation/Foundation/NSOrderedCollectionDifference/init(insert:insertedObjects:remove:removedObjects:))

Creates an ordered collection difference from arrays of inserted and removed objects with corresponding sets of indices.

[`-  initWithInsertIndexes:insertedObjects:removeIndexes:removedObjects:additionalChanges:`](/documentation/Foundation/NSOrderedCollectionDifference/init(insert:insertedObjects:remove:removedObjects:additionalChanges:))

Creates an ordered collection difference from arrays of inserted and removed objects with corresponding sets of indices, in addition to an array of ordered collection changes.

### Updating Changes from a Difference Object

[`-  differenceByTransformingChangesWithBlock:`](/documentation/Foundation/NSOrderedCollectionDifference/transformingChanges(_:))

Create a new ordered collection difference by mapping over this difference’s members, processing the change objects with the block provided.

## Relationships

### Conforms To

[`Hashable`](/documentation/Swift/Hashable)

[`CVarArg`](/documentation/Swift/CVarArg)

[`NSFastEnumeration`](/documentation/Foundation/NSFastEnumeration)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)