NSDiffableDataSourceSectionSnapshot
A representation of the state of the data in a layout section at a specific point in time.
Declaration
@preconcurrency struct NSDiffableDataSourceSectionSnapshot<ItemIdentifierType> where ItemIdentifierType : Hashable, ItemIdentifierType : SendableOverview
A section snapshot represents the data for a single section in a collection view. Through a section snapshot, you set up the initial state of the data that displays in an individual section of your view, and later update that data.
You can use section snapshots with or instead of an NSDiffableDataSourceSnapshot, which represents the data in the entire view. Use a section snapshot when you need precise management of the data in a section of your layout, such as when the sections of your layout acquire their data from different sources. You can also use a section snapshot to represent data with a hierarchical structure, such as an outline with expandable items.
The following example creates a section snapshot with two root items, with one that contains three child items:
for section in Section.allCases {
// Create a section snapshot
var sectionSnapshot = NSDiffableDataSourceSectionSnapshot<String>()
// Populate the section snapshot
sectionSnapshot.append(["Food", "Drinks"])
sectionSnapshot.append(["๐", "๐", "๐ฅ"], to: "Food")
// Apply the section snapshot
dataSource.apply(sectionSnapshot,
to: section,
animatingDifferences: true)
}