<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: -",
    "tvOS: 13.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "s:5UIKit34UICollectionViewDiffableDataSourceC"
  },
  "title" : "UICollectionViewDiffableDataSource"
}
-->

# UICollectionViewDiffableDataSource

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

```
@MainActor @preconcurrency class UICollectionViewDiffableDataSource<SectionIdentifierType, ItemIdentifierType> where SectionIdentifierType : Hashable, SectionIdentifierType : Sendable, ItemIdentifierType : Hashable, ItemIdentifierType : Sendable
```

## 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 [`UICollectionViewDataSource`](/documentation/UIKit/UICollectionViewDataSource) 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 a cell provider to configure your collection view’s cells.
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:cellProvider:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/init(collectionView:cellProvider:)) initializer, passing in the collection view you want to associate with that data source. You also pass in a cell provider, where you configure each of your cells to determine how to display your data in the UI.

```swift
dataSource = UICollectionViewDiffableDataSource<Int, UUID>(collectionView: collectionView) {
    (collectionView: UICollectionView, indexPath: IndexPath, itemIdentifier: UUID) -> UICollectionViewCell? in
    // Configure and return cell.
}
```

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/UIKit/NSDiffableDataSourceSnapshot-swift.struct).

> Important:
> Don’t change the ``doc://com.apple.uikit/documentation/UIKit/UITableView/dataSource`` on the collection view after you configure it with a diffable data source. If the collection view needs a new data source after you configure it initially, create and configure a new collection view and diffable data source.

## Topics

### Creating a diffable data source

[`init(collectionView:cellProvider:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/init(collectionView:cellProvider:))

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

[`UICollectionViewDiffableDataSource.CellProvider`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/CellProvider)

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

### Creating supplementary views

[`supplementaryViewProvider`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/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.

[`UICollectionViewDiffableDataSource.SupplementaryViewProvider`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/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/UIKit/UICollectionViewDiffableDataSource-9tqpa/itemIdentifier(for:))

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

[`indexPath(for:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/indexPath(for:))

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

### Identifying sections

[`sectionIdentifier(for:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/sectionIdentifier(for:))

Returns an identifier for the section at the index you specify in the collection view.

[`index(for:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/index(for:))

Returns an index for the section with the identifier you specify in the collection view.

### Updating data

[`snapshot()`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/snapshot())

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

[`apply(_:animatingDifferences:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/apply(_:animatingDifferences:))

Updates the UI to reflect the state of the data in the snapshot, optionally animating the UI changes.

[`apply(_:animatingDifferences:completion:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/apply(_:animatingDifferences:completion:))

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

[`applySnapshotUsingReloadData(_:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/applySnapshotUsingReloadData(_:))

Resets the UI to reflect the state of the data in the snapshot without computing a diff or animating the changes.

[`applySnapshotUsingReloadData(_:completion:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/applySnapshotUsingReloadData(_:completion:))

Resets the UI to reflect the state of the data in the snapshot without computing a diff or animating the changes, optionally executing a completion handler.

### Updating section data

[`snapshot(for:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/snapshot(for:))

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

[`apply(_:to:animatingDifferences:completion:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/apply(_:to:animatingDifferences:completion:))

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

[`apply(_:to:animatingDifferences:)`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/apply(_:to:animatingDifferences:))

Updates the section UI to reflect the state of the data in the specified snapshot, optionally animating the UI changes.

### Supporting reordering

[`reorderingHandlers`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/reorderingHandlers-swift.property)

The diffable data source’s handlers for reordering items.

[`UICollectionViewDiffableDataSource.ReorderingHandlers`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/ReorderingHandlers-swift.struct)

Handlers for reordering items.

[`NSDiffableDataSourceTransaction`](/documentation/UIKit/NSDiffableDataSourceTransaction-swift.struct)

A transaction that describes the changes after reordering the items in the view.

[`NSDiffableDataSourceSectionTransaction`](/documentation/UIKit/NSDiffableDataSourceSectionTransaction-swift.struct)

A transaction that describes the changes after reordering the items in a section.

### Supporting expanding and collapsing

[`sectionSnapshotHandlers`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/sectionSnapshotHandlers-swift.property)

The diffable data source’s handlers for expanding and collapsing items.

[`UICollectionViewDiffableDataSource.SectionSnapshotHandlers`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/SectionSnapshotHandlers-swift.struct)

Handlers for expanding and collapsing items.

### Debugging a diffable data source

[`description()`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/description())

Returns a string with a description of the diffable data source.

### Supporting bridging

[`UICollectionViewDiffableDataSourceReference`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference)

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



---

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)