---
title: NSDiffableDataSourceSnapshot
framework: uikit
role: symbol
role_heading: Structure
path: uikit/nsdiffabledatasourcesnapshot-swift.struct
---

# NSDiffableDataSourceSnapshot

A representation of the state of the data in a view at a specific point in time.

## Declaration

```swift
@preconcurrency struct NSDiffableDataSourceSnapshot<SectionIdentifierType, ItemIdentifierType> where SectionIdentifierType : Hashable, SectionIdentifierType : Sendable, ItemIdentifierType : Hashable, ItemIdentifierType : Sendable
```

## Overview

Overview Diffable data sources use snapshots to provide data for collection views and table views. You use a snapshot to set up the initial state of the data that a view displays, and you use snapshots to reflect changes to the data that the view displays. The data in a snapshot is made up of the sections and items you want to display, in the order that you determine. You configure what to display by adding, deleting, or moving the sections and items. important: Each of your sections and items must have unique identifiers that conform to the Hashable protocol. Use struct or enum Swift value types for your identifiers, including built-in types such as Int, String, or UUID. If you use a Swift class for your identifiers, your class must be a subclass of NSObject. 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, the code applies the snapshot, animating the UI updates between the previous state and the new state. // Create a snapshot. var snapshot = NSDiffableDataSourceSnapshot<Int, UUID>()

// Populate the snapshot. snapshot.appendSections([0]) snapshot.appendItems([UUID(), UUID(), UUID()])

// Apply the snapshot. dataSource.apply(snapshot, animatingDifferences: true) For more information, see the diffable data source types: UICollectionViewDiffableDataSource UITableViewDiffableDataSource NSCollectionViewDiffableDataSource Bridging You can bridge from an NSDiffableDataSourceSnapshotReference object to this type: let snapshot = snapshotReference as NSDiffableDataSourceSnapshot<Int, UUID>

## Topics

### Creating a snapshot

- [init()](uikit/nsdiffabledatasourcesnapshot-swift.struct/init().md)
- [appendSections(_:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/appendsections(_:).md)
- [appendItems(_:toSection:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/appenditems(_:tosection:).md)

### Getting item and section metrics

- [numberOfItems](uikit/nsdiffabledatasourcesnapshot-swift.struct/numberofitems.md)
- [numberOfSections](uikit/nsdiffabledatasourcesnapshot-swift.struct/numberofsections.md)
- [numberOfItems(inSection:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/numberofitems(insection:).md)

### Identifying items and sections

- [itemIdentifiers](uikit/nsdiffabledatasourcesnapshot-swift.struct/itemidentifiers.md)
- [sectionIdentifiers](uikit/nsdiffabledatasourcesnapshot-swift.struct/sectionidentifiers.md)
- [indexOfItem(_:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/indexofitem(_:).md)
- [indexOfSection(_:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/indexofsection(_:).md)
- [itemIdentifiers(inSection:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/itemidentifiers(insection:).md)
- [sectionIdentifier(containingItem:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/sectionidentifier(containingitem:).md)

### Inserting items and sections

- [insertItems(_:afterItem:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/insertitems(_:afteritem:).md)
- [insertItems(_:beforeItem:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/insertitems(_:beforeitem:).md)
- [insertSections(_:afterSection:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/insertsections(_:aftersection:).md)
- [insertSections(_:beforeSection:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/insertsections(_:beforesection:).md)

### Removing items and sections

- [deleteAllItems()](uikit/nsdiffabledatasourcesnapshot-swift.struct/deleteallitems().md)
- [deleteItems(_:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/deleteitems(_:).md)
- [deleteSections(_:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/deletesections(_:).md)

### Reordering items and sections

- [moveItem(_:afterItem:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/moveitem(_:afteritem:).md)
- [moveItem(_:beforeItem:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/moveitem(_:beforeitem:).md)
- [moveSection(_:afterSection:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/movesection(_:aftersection:).md)
- [moveSection(_:beforeSection:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/movesection(_:beforesection:).md)

### Reloading data

- [reconfigureItems(_:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/reconfigureitems(_:).md)
- [reconfiguredItemIdentifiers](uikit/nsdiffabledatasourcesnapshot-swift.struct/reconfigureditemidentifiers.md)
- [reloadItems(_:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/reloaditems(_:).md)
- [reloadedItemIdentifiers](uikit/nsdiffabledatasourcesnapshot-swift.struct/reloadeditemidentifiers.md)
- [reloadSections(_:)](uikit/nsdiffabledatasourcesnapshot-swift.struct/reloadsections(_:).md)
- [reloadedSectionIdentifiers](uikit/nsdiffabledatasourcesnapshot-swift.struct/reloadedsectionidentifiers.md)

### Supporting bridging

- [NSDiffableDataSourceSnapshotReference](uikit/nsdiffabledatasourcesnapshotreference.md)

## Relationships

### Conforms To

- [Copyable](swift/copyable.md)
- [Escapable](swift/escapable.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)

## See Also

### Data

- [Updating collection views using diffable data sources](uikit/updating-collection-views-using-diffable-data-sources.md)
- [Implementing modern collection views](uikit/implementing-modern-collection-views.md)
- [Building high-performance lists and collection views](uikit/building-high-performance-lists-and-collection-views.md)
- [UICollectionViewDiffableDataSource](uikit/uicollectionviewdiffabledatasource-9tqpa.md)
- [UICollectionViewDataSource](uikit/uicollectionviewdatasource.md)
- [UICollectionViewDataSourcePrefetching](uikit/uicollectionviewdatasourceprefetching.md)
- [NSDiffableDataSourceSectionSnapshot](uikit/nsdiffabledatasourcesectionsnapshot-swift.struct.md)
- [UIRefreshControl](uikit/uirefreshcontrol.md)
