<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/CollectionDifference/init(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s20CollectionDifferenceVyAByxGSgqd__cSlRd__AB6ChangeOyx_G7ElementRtd__lufc"
  },
  "title" : "init(_:)"
}
-->

# init(_:)

Creates a new collection difference from a collection of changes.

```
init?<Changes>(_ changes: Changes) where Changes : Collection, Changes.Element == CollectionDifference<ChangeElement>.Change
```

## Parameters

`changes`

A collection of changes that represent a transition
between two states.

## Discussion

To find the difference between two collections, use the
`difference(from:)` method declared on the `BidirectionalCollection`
protocol.

The collection of changes passed as `changes` must meet these
requirements:

- All insertion offsets are unique
- All removal offsets are unique
- All associations between insertions and removals are symmetric

> Complexity: O(*n* * log(*n*)), where *n* is the length of the
> parameter.

---

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)