Generic Initializer

init(_:)

Creates a new collection difference from a collection of changes.

Declaration

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:

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

  • All insertion offsets are unique

  • All removal offsets are unique

  • All associations between insertions and removals are symmetric