<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UICollectionViewDiffableDataSourceReference",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UICollectionViewDiffableDataSource"
  },
  "title" : "UICollectionViewDiffableDataSourceReference"
}
-->

# UICollectionViewDiffableDataSourceReference

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

```
@MainActor class UICollectionViewDiffableDataSourceReference
```

## Overview> Important: If you’re working in a Swift codebase, always use ``doc://com.apple.uikit/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa`` instead.

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/UICollectionViewDiffableDataSourceReference/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.

```objc
self.dataSource = [[UICollectionViewDiffableDataSource alloc] initWithCollectionView:self.collectionView cellProvider:^UICollectionViewCell *(UICollectionView *collectionView, NSIndexPath *indexPath, id item) {
    // 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 [`NSDiffableDataSourceSnapshotReference`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference).

> Important:
> Don’t change the ``doc://com.apple.uikit/documentation/UIKit/UICollectionView/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

[`-  initWithCollectionView:cellProvider:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/init(collectionView:cellProvider:))

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

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

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

### Creating supplementary views

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

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

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

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

[`-  itemIdentifierForIndexPath:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/itemIdentifier(for:))

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

[`-  indexPathForItemIdentifier:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/indexPath(forItemIdentifier:))

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

### Identifying sections

[`-  sectionIdentifierForIndex:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/sectionIdentifier(for:))

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

[`-  indexForSectionIdentifier:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/index(forSectionIdentifier:))

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

### Updating data

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

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

[`-  applySnapshot:animatingDifferences:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/applySnapshot(_:animatingDifferences:))

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

[`-  applySnapshot:animatingDifferences:completion:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/applySnapshot(_: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/UICollectionViewDiffableDataSourceReference/applySnapshot(usingReloadData:))

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/UICollectionViewDiffableDataSourceReference/applySnapshot(usingReloadData: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

[`-  snapshotForSection:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/snapshot(forSection:))

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

[`-  applySnapshot:toSection:animatingDifferences:completion:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/applySnapshot(_:toSection: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.

[`-  applySnapshot:toSection:animatingDifferences:`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference/applySnapshot(_:toSection: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/UICollectionViewDiffableDataSourceReference/reorderingHandlers)

The diffable data source’s handlers for reordering items.

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

Handlers for reordering items.

[`NSDiffableDataSourceTransaction`](/documentation/UIKit/NSDiffableDataSourceTransaction-c.class)

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

[`NSDiffableDataSourceSectionTransaction`](/documentation/UIKit/NSDiffableDataSourceSectionTransaction-c.class)

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

### Supporting expanding and collapsing

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

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

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

Handlers for expanding and collapsing items.

## Relationships

### Conforms To

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

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

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`Sendable`](/documentation/Swift/Sendable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)