A representation of the state of the data in a view at a specific point in time.
- macOS 10.15.1+
- Xcode 11.2+
Diffable data sources use snapshots to provide data for collection views and table views. Through a snapshot, you set up the initial state of the data displayed in a view, and later update that data.
The data in a snapshot is made up of the sections and items you want to display, in the specific order you want to display them. You configure what to display by adding, deleting, or moving the sections and items.
To display data in a view using a snapshot:
Create a snapshot and populate it with the state of the data you want to display.
Apply the snapshot to reflect the changes in the UI.
You can create and configure a snapshot in one of these ways:
Create an empty snapshot, then append sections and items to it.
Get the current snapshot by calling the diffable data source's
snapshot()method, then modify that snapshot to reflect the new state of the data that you want to display.
For example, the following code creates an empty snapshot, and populates it with a single section with three items. Then, it applies the snapshot, animating the UI updates between the previous state and the new state represented in the snapshot.
For more information, see the diffable data source types:
You can bridge from an
NSDiffable object to this type: