<!--
{
  "availability" : [
    "macOS: 10.15.1 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/apply(_:animatingDifferences:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "s:6AppKit34NSCollectionViewDiffableDataSourceC5apply_20animatingDifferences10completionyAA010NSDiffablefG8SnapshotVyxq_G_SbyycSgtF"
  },
  "title" : "apply(_:animatingDifferences:completion:)"
}
-->

# apply(_:animatingDifferences:completion:)

Updates the UI to reflect the state of the data in the specified snapshot, optionally animating the UI changes and executing a completion handler.

```
func apply(_ snapshot: NSDiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType>, animatingDifferences: Bool = true, completion: (() -> Void)? = nil)
```

## Parameters

`snapshot`

The snapshot reflecting the new state of the data in the collection view.

`animatingDifferences`

If <doc://com.apple.documentation/documentation/Swift/true>, the diffable data source computes the difference between the collection view’s current state and the new state in the snapshot, which is an O(*n*) operation, where *n* is the number of items in the snapshot. The differences in the UI between the current state and new state are animated. If <doc://com.apple.documentation/documentation/Swift/false>, the collection view UI is set to the new state without any animations, with no additional overhead for computing a diff. Any ongoing item animations are interrupted and the collection view’s content is reloaded immediately.

`completion`

A closure to be executed when the animations are complete. This closure has no return value and takes no parameters. The system calls this closure from the main queue.

## Discussion

It’s safe to call this method from a background queue, but you must do so consistently in your app. Always call this method exclusively from the main queue or from a background queue.

---

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)