<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDiffableDataSourceSectionSnapshot"
  },
  "title" : "NSDiffableDataSourceSectionSnapshotReference"
}
-->

# NSDiffableDataSourceSectionSnapshotReference

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

```
class NSDiffableDataSourceSectionSnapshotReference
```

## Overview

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 [`NSDiffableDataSourceSnapshotReference`](/documentation/UIKit/NSDiffableDataSourceSnapshotReference), 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 one root item that contains three child items:

```objc
for (NSNumber *section in sections) {
    // Create a section snapshot.
    NSDiffableDataSourceSectionSnapshot<NSString *> *sectionSnapshot = [[NSDiffableDataSourceSectionSnapshot alloc] init];
    
    // Populate the section snapshot.
    [sectionSnapshot appendItems: @[@"Food", @"Drinks"]];
    [sectionSnapshot appendItems: @[@"🍏", @"🍓", @"🥐"] intoParentItem: @"Food"];
    
    // Apply the section snapshot.
    [dataSource applySnapshot: sectionSnapshot
                    toSection: section
         animatingDifferences: YES];
}
```

> Important: If you’re working in a Swift codebase, always use ``doc://com.apple.uikit/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-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 section snapshot reference to a section snapshot:

```swift
let sectionSnapshot = sectionSnapshotRef as NSDiffableDataSourceSectionSnapshot<UUID>
```

## Topics

### Creating a section snapshot

[`init()`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/init())

Creates an empty section snapshot.

[`func ofParentItem(Any) -> NSDiffableDataSourceSectionSnapshotReference`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/ofParentItem(_:))

Creates a section snapshot containing the child items of the specified parent item, excluding the parent item.

[`func ofParentItem(Any, includingParentItem: Bool) -> NSDiffableDataSourceSectionSnapshotReference`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/ofParentItem(_:includingParentItem:))

Creates a section snapshot containing the child items of the specified parent item, including the parent item.

[`func appendItems([Any])`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/appendItems(_:))

Adds the specified items to the section snapshot.

[`func appendItems([Any], intoParentItem: Any?)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/appendItems(_:intoParentItem:))

Adds the specified items as child items of the specified parent item in the section snapshot.

### Accessing items

[`var items: [Any]`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/items)

The identifiers of all items in the section snapshot.

[`var rootItems: [Any]`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/rootItems)

The identifiers of the items at the top level of the section snapshot’s hierarchy.

[`var visibleItems: [Any]`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/visibleItems)

The identifiers of the currently visible items in the section snapshot.

### Getting item metrics

[`func index(ofItem: Any) -> Int`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/index(ofItem:))

Finds the index of the specified item in the section snapshot.

[`func level(ofItem: Any) -> Int`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/level(ofItem:))

Finds the hierarchical level of the specified item in the section snapshot.

[`func parent(ofChildItem: Any) -> Any?`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/parent(ofChildItem:))

Finds the parent item of the specified item in the section snapshot.

[`func containsItem(Any) -> Bool`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/containsItem(_:))

Indicates whether the section snapshot contains the specified item.

[`func isVisible(Any) -> Bool`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/isVisible(_:))

Indicates whether the specified item is currently visible onscreen.

### Inserting items

[`func insert(NSDiffableDataSourceSectionSnapshotReference, afterItem: Any) -> Any`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/insert(_:afterItem:))

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

[`func insertItems([Any], afterItem: Any)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/insertItems(_:afterItem:))

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

[`func insert(NSDiffableDataSourceSectionSnapshotReference, beforeItem: Any)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/insert(_:beforeItem:))

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

[`func insertItems([Any], beforeItem: Any)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/insertItems(_:beforeItem:))

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

### Removing items

[`func deleteItems([Any])`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/deleteItems(_:))

Deletes the items with the specified identifiers, and any of their child items, from the section snapshot.

[`func deleteAllItems()`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/deleteAllItems())

Deletes all of the items from the section snapshot.

### Replacing items

[`func replaceChildren(ofParentItem: Any, with: NSDiffableDataSourceSectionSnapshotReference)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/replaceChildren(ofParentItem:with:))

Replaces all child items of the specified parent item with the provided section snapshot.

### Expanding and collapsing items

[`func isExpanded(Any) -> Bool`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/isExpanded(_:))

Indicates whether the item with the specified identifier is in an expanded state.

[`func expandItems([Any])`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/expandItems(_:))

Expands the specified items in the section snapshot.

[`func collapseItems([Any])`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/collapseItems(_:))

Collapses the specified items in the section snapshot.

### Debugging section snapshots

[`func visualDescription() -> String`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/visualDescription())

Returns a string with an ASCII representation of the section snapshot.

### Instance Methods

[`func expandedItems() -> [Any]`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshotReference/expandedItems())

The identifiers of all expanded items in the section snapshot.

## Relationships

### Inherits From

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

### Conforms To

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

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

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

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

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

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

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

---

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)