<!--
{
  "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/UInt/Words-swift.struct/difference(from:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SKsSQ7ElementRpzrlE10difference4froms20CollectionDifferenceVyABGqd___tSKRd__AAQyd__ABRSlF::SYNTHESIZED::s:Su5WordsV"
  },
  "title" : "difference(from:)"
}
-->

# difference(from:)

Returns the difference needed to produce this collection’s ordered
elements from the given collection.

```
func difference<C>(from other: C) -> CollectionDifference<Self.Element> where C : BidirectionalCollection, Self.Element == C.Element
```

## Parameters

`other`

The base state.

## Return Value

The difference needed to produce this collection’s ordered
elements from the given collection.

## Discussion

This function does not infer element moves. If you need to infer moves,
call the `inferringMoves()` method on the resulting difference.

> Complexity: Worst case performance is O(*n* * *m*), where *n* is the
> count of this collection and *m* is `other.count`. You can expect
> faster execution when the collections share many common elements, or
> if `Element` conforms to `Hashable`.

---

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)