Contents

UITableViewDiffableDataSourceReference

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

Declaration

@MainActor class UITableViewDiffableDataSourceReference

Overview

A diffable data source object is a specialized type of data source that works together with your table view object. It provides the behavior you need to manage updates to your table view’s data and UI in a simple, efficient way. It also conforms to the UITableViewDataSource protocol and provides implementations for all of the protocol’s methods.

To fill a table view with data:

  1. Connect a diffable data source to your table view.

  2. Implement a cell provider to configure your table 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 table view, you create the diffable data source using its init(tableView:cellProvider:) initializer, passing in the table 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.

self.dataSource = [[UITableViewDiffableDataSource alloc] initWithTableView:self.tableView cellProvider:^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath, id itemIdentifier) {
    // 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.

Topics

Creating a diffable data source

Identifying items

Identifying sections

Updating data