<!--
{
  "availability" : [
    "macOS: 10.15.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSDiffableDataSourceSnapshotReference",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "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> Important:
> If you’re working in a Swift codebase, always use ``doc://com.apple.appkit/documentation/AppKit/NSDiffableDataSourceSnapshot-swift.struct`` instead of `NSDiffableDataSourceSnapshotReference`.

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 that displays 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.

> Important:
> Each of your sections and items must have unique identifiers.

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/AppKit/NSCollectionViewDiffableDataSourceReference/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.

```swift
// 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:

- <doc://com.apple.documentation/documentation/UIKit/UICollectionViewDiffableDataSource-9tqpa>
- <doc://com.apple.documentation/documentation/UIKit/UITableViewDiffableDataSource-2euir>
- [`NSCollectionViewDiffableDataSourceReference`](/documentation/AppKit/NSCollectionViewDiffableDataSourceReference)

### Bridging

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

[`func appendSections(withIdentifiers: [Any])`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/appendSections(withIdentifiers:))

Adds the sections with the specified identifiers to the snapshot.

[`func appendItems(withIdentifiers: [Any], intoSectionWithIdentifier: Any)`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/appendItems(withIdentifiers:intoSectionWithIdentifier:))

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

[`func appendItems(withIdentifiers: [Any])`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/appendItems(withIdentifiers:))

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

### Getting item and section metrics

[`var numberOfItems: Int`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/numberOfItems)

The number of items in the snapshot.

[`var numberOfSections: Int`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/numberOfSections)

The number of sections in the snapshot.

[`func numberOfItems(inSection: Any) -> Int`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/numberOfItems(inSection:))

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

### Identifying items and sections

[`var itemIdentifiers: [Any]`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/itemIdentifiers)

The identifiers of all of the items in the snapshot.

[`var sectionIdentifiers: [Any]`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/sectionIdentifiers)

The identifiers of all of the sections in the snapshot.

[`func index(ofItemIdentifier: Any) -> Int`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/index(ofItemIdentifier:))

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

[`func index(ofSectionIdentifier: Any) -> Int`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/index(ofSectionIdentifier:))

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

[`func itemIdentifiersInSection(withIdentifier: Any) -> [Any]`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/itemIdentifiersInSection(withIdentifier:))

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

[`func sectionIdentifier(forSectionContainingItemIdentifier: Any) -> Any?`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/sectionIdentifier(forSectionContainingItemIdentifier:))

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

### Inserting items and sections

[`func insertItems(withIdentifiers: [Any], afterItemWithIdentifier: Any)`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/insertItems(withIdentifiers:afterItemWithIdentifier:))

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

[`func insertItems(withIdentifiers: [Any], beforeItemWithIdentifier: Any)`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/insertItems(withIdentifiers:beforeItemWithIdentifier:))

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

[`func insertSections(withIdentifiers: [Any], afterSectionWithIdentifier: Any)`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/insertSections(withIdentifiers:afterSectionWithIdentifier:))

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

[`func insertSections(withIdentifiers: [Any], beforeSectionWithIdentifier: Any)`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/insertSections(withIdentifiers:beforeSectionWithIdentifier:))

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

### Removing items and sections

[`func deleteAllItems()`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/deleteAllItems())

Deletes all of the items from the snapshot.

[`func deleteItems(withIdentifiers: [Any])`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/deleteItems(withIdentifiers:))

Deletes the items with the specified identifiers from the snapshot.

[`func deleteSections(withIdentifiers: [Any])`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/deleteSections(withIdentifiers:))

Deletes the sections with the specified identifiers from the snapshot.

### Reordering items and sections

[`func moveItem(withIdentifier: Any, afterItemWithIdentifier: Any)`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/moveItem(withIdentifier:afterItemWithIdentifier:))

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

[`func moveItem(withIdentifier: Any, beforeItemWithIdentifier: Any)`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/moveItem(withIdentifier:beforeItemWithIdentifier:))

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

[`func moveSection(withIdentifier: Any, afterSectionWithIdentifier: Any)`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/moveSection(withIdentifier:afterSectionWithIdentifier:))

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

[`func moveSection(withIdentifier: Any, beforeSectionWithIdentifier: Any)`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/moveSection(withIdentifier:beforeSectionWithIdentifier:))

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

### Reloading data

[`func reloadItems(withIdentifiers: [Any])`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/reloadItems(withIdentifiers:))

Reloads the data within the specified items in the snapshot.

[`func reloadSections(withIdentifiers: [Any])`](/documentation/AppKit/NSDiffableDataSourceSnapshotReference/reloadSections(withIdentifiers:))

Reloads the data within the specified sections of the snapshot.

## Relationships

### Conforms To

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)