<!--
{
  "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/NSDiffableDataSourceSnapshotReference",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDiffableDataSourceSnapshot"
  },
  "title" : "NSDiffableDataSourceSnapshotReference"
}
-->

# NSDiffableDataSourceSnapshotReference

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

```
class NSDiffableDataSourceSnapshotReference
```

## 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 <doc://com.apple.documentation/documentation/Swift/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:

1. Create a snapshot and populate it with the state of the data you want to display.
2. 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()`](/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa/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.

```objc
// Create a snapshot.
NSDiffableDataSourceSnapshot<NSNumber *, NSUUID *> *snapshot = [[NSDiffableDataSourceSnapshot alloc] init];


// Populate the snapshot.
[snapshot appendSectionsWithIdentifiers:@[@0]];
[snapshot appendItemsWithIdentifiers:@[[NSUUID UUID], [NSUUID UUID], [NSUUID UUID]]];


// Apply the snapshot.
[self.dataSource applySnapshot:snapshot animatingDifferences:YES];
```

For more information, see the diffable data source types:

- [`UICollectionViewDiffableDataSourceReference`](/documentation/UIKit/UICollectionViewDiffableDataSourceReference)
- [`UITableViewDiffableDataSourceReference`](/documentation/UIKit/UITableViewDiffableDataSourceReference)
- <doc://com.apple.documentation/documentation/AppKit/NSCollectionViewDiffableDataSource-axww>

> Important: If you’re working in a Swift codebase, always use ``doc://com.apple.uikit/documentation/UIKit/NSDiffableDataSourceSnapshot-swift.struct`` instead.

Avoid using this type in Swift code. Only use this type to bridge from Objective-C code to Swift code by typecasting from a snapshot reference to a snapshot:

```swift
let snapshot = snapshotReference as NSDiffableDataSourceSnapshot<Int, UUID>
```

## Topics

### Creating a snapshot

[`appendSections(withIdentifiers:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/appendSections(withIdentifiers:))

Adds the sections with the specified identifiers to the snapshot.

[`appendItems(withIdentifiers:intoSectionWithIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/appendItems(withIdentifiers:intoSectionWithIdentifier:))

Adds the items with the specified identifiers to the specified section of the snapshot.

[`appendItems(withIdentifiers:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/appendItems(withIdentifiers:))

Adds the items with the specified identifiers to the last section of the snapshot.

### Getting item and section metrics

[`numberOfItems`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/numberOfItems)

The number of items in the snapshot.

[`numberOfSections`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/numberOfSections)

The number of sections in the snapshot.

[`numberOfItems(inSection:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/numberOfItems(inSection:))

Returns the number of items in the specified section of the snapshot.

### Identifying items and sections

[`itemIdentifiers`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/itemIdentifiers)

The identifiers of all of the items in the snapshot.

[`sectionIdentifiers`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/sectionIdentifiers)

The identifiers of all of the sections in the snapshot.

[`index(ofItemIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/index(ofItemIdentifier:))

Returns the index of the item in the snapshot with the specified identifier.

[`index(ofSectionIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/index(ofSectionIdentifier:))

Returns the index of the section of the snapshot with the specified identifier.

[`itemIdentifiersInSection(withIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/itemIdentifiersInSection(withIdentifier:))

Returns the identifiers of all of the items in the specified section of the snapshot.

[`sectionIdentifier(forSectionContainingItemIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/sectionIdentifier(forSectionContainingItemIdentifier:))

Returns the identifier of the section containing the specified item in the snapshot.

### Inserting items and sections

[`insertItems(withIdentifiers:afterItemWithIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/insertItems(withIdentifiers:afterItemWithIdentifier:))

Inserts the provided items immediately after the item with the specified identifier in the snapshot.

[`insertItems(withIdentifiers:beforeItemWithIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/insertItems(withIdentifiers:beforeItemWithIdentifier:))

Inserts the provided items immediately before the item with the specified identifier in the snapshot.

[`insertSections(withIdentifiers:afterSectionWithIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/insertSections(withIdentifiers:afterSectionWithIdentifier:))

Inserts the provided sections immediately after the section with the specified identifier in the snapshot.

[`insertSections(withIdentifiers:beforeSectionWithIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/insertSections(withIdentifiers:beforeSectionWithIdentifier:))

Inserts the provided sections immediately before the section with the specified identifier in the snapshot.

### Removing items and sections

[`deleteAllItems()`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/deleteAllItems())

Deletes all of the items from the snapshot.

[`deleteItems(withIdentifiers:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/deleteItems(withIdentifiers:))

Deletes the items with the specified identifiers from the snapshot.

[`deleteSections(withIdentifiers:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/deleteSections(withIdentifiers:))

Deletes the sections with the specified identifiers from the snapshot.

### Reordering items and sections

[`moveItem(withIdentifier:afterItemWithIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/moveItem(withIdentifier:afterItemWithIdentifier:))

Moves the item from its current position in the snapshot to the position immediately after the specified item.

[`moveItem(withIdentifier:beforeItemWithIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/moveItem(withIdentifier:beforeItemWithIdentifier:))

Moves the item from its current position in the snapshot to the position immediately before the specified item.

[`moveSection(withIdentifier:afterSectionWithIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/moveSection(withIdentifier:afterSectionWithIdentifier:))

Moves the section from its current position in the snapshot to the position immediately after the specified section.

[`moveSection(withIdentifier:beforeSectionWithIdentifier:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/moveSection(withIdentifier:beforeSectionWithIdentifier:))

Moves the section from its current position in the snapshot to the position immediately before the specified section.

### Reloading data

[`reconfigureItems(withIdentifiers:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/reconfigureItems(withIdentifiers:))

Updates the data for the items you specify in the snapshot, preserving the existing cells for the items.

[`reconfiguredItemIdentifiers`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/reconfiguredItemIdentifiers)

Identifies the items reconfigured by the changes to the snapshot.

[`reloadItems(withIdentifiers:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/reloadItems(withIdentifiers:))

Reloads the data within the specified items in the snapshot.

[`reloadedItemIdentifiers`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/reloadedItemIdentifiers)

Identifies the items reloaded by the changes to the snapshot.

[`reloadSections(withIdentifiers:)`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/reloadSections(withIdentifiers:))

Reloads the data within the specified sections of the snapshot.

[`reloadedSectionIdentifiers`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference/reloadedSectionIdentifiers)

Identifies the sections reloaded by the changes to the snapshot.



---

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)