<!--
{
  "availability" : [
    "macOS: 10.15.1 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSCollectionViewDiffableDataSource-axww",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "s:6AppKit34NSCollectionViewDiffableDataSourceC"
  },
  "title" : "NSCollectionViewDiffableDataSource"
}
-->

# NSCollectionViewDiffableDataSource

The object you use to manage data and provide items for a collection view.

```
class NSCollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> where SectionIdentifierType : Hashable, ItemIdentifierType : Hashable
```

## Overview

A *diffable data source* object is a specialized type of data source that works together with your collection view object. It provides the behavior you need to manage updates to your collection view’s data and UI in a simple, efficient way. It also conforms to the [`NSCollectionViewDataSource`](/documentation/AppKit/NSCollectionViewDataSource) protocol and provides implementations for all of the protocol’s methods.

To fill a collection view with data:

1. Connect a diffable data source to your collection view.
2. Implement an item provider to configure your collection view’s items.
3. Generate the current state of the data.
4. Display the data in the UI.

To connect a diffable data source to a collection view, you create the diffable data source using its [`init(collectionView:itemProvider:)`](/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/init(collectionView:itemProvider:)) initializer, passing in the collection view you want to associate with that data source. You also pass in an item provider, where you configure each of your items to determine how to display your data in the UI.

```swift
dataSource = NSCollectionViewDiffableDataSource<Int, UUID>(collectionView: collectionView) {
    (collectionView: NSCollectionView, indexPath: IndexPath, itemIdentifier: UUID) -> NSCollectionViewItem? in
    // configure and return item
}
```

Then, you generate the current state of the data and display the data in the UI by constructing and applying a snapshot. For more information, see [`NSDiffableDataSourceSnapshot`](/documentation/AppKit/NSDiffableDataSourceSnapshot-swift.struct).

## Topics

### Creating a Diffable Data Source

[`init(collectionView:itemProvider:)`](/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/init(collectionView:itemProvider:))

Creates a diffable data source with the specified item provider, and connects it to the specified collection view.

[`NSCollectionViewDiffableDataSource.ItemProvider`](/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/ItemProvider)

A closure that configures and returns an item for a collection view from its diffable data source.

### Creating Supplementary Views

[`supplementaryViewProvider`](/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/supplementaryViewProvider-swift.property)

The closure that configures and returns the collection view’s supplementary views, such as headers and footers, from the diffable data source.

[`NSCollectionViewDiffableDataSource.SupplementaryViewProvider`](/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/SupplementaryViewProvider-swift.typealias)

A closure that configures and returns a collection view’s supplementary view, such as a header or footer, from a diffable data source.

### Identifying Items

[`itemIdentifier(for:)`](/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/itemIdentifier(for:))

Returns an identifier for the item at the specified index path in the collection view.

[`indexPath(for:)`](/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/indexPath(for:))

Returns an index path for the item with the specified identifier in the collection view.

### Updating Data

[`snapshot()`](/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/snapshot())

Returns a representation of the current state of the data in the collection view.

[`apply(_:animatingDifferences:completion:)`](/documentation/AppKit/NSCollectionViewDiffableDataSource-axww/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.

### Supporting Protocol Requirements

[Protocol Implementations](/documentation/AppKit/protocol-implementations)

Access the diffable data source’s implementations of protocol methods.



---

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)