<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "tvOS: 14.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "s:5UIKit35NSDiffableDataSourceSectionSnapshotV"
  },
  "title" : "NSDiffableDataSourceSectionSnapshot"
}
-->

# NSDiffableDataSourceSectionSnapshot

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

```
@preconcurrency struct NSDiffableDataSourceSectionSnapshot<ItemIdentifierType> where ItemIdentifierType : Hashable, ItemIdentifierType : Sendable
```

## 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 [`NSDiffableDataSourceSnapshot`](/documentation/UIKit/NSDiffableDataSourceSnapshot-swift.struct), 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:

```swift
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)
}
```

## Topics

### Creating a section snapshot

[`init()`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/init())

Creates an empty section snapshot.

[`init(_:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/init(_:))

Creates a copy of the provided section snapshot.

[`snapshot(of:includingParent:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/snapshot(of:includingParent:))

Creates a section snapshot that contains the child items of the specified parent item, optionally including the parent item.

[`append(_:to:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/append(_:to:))

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

### Accessing items

[`items`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/items)

The identifiers of all items in the section snapshot.

[`rootItems`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/rootItems)

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

[`visibleItems`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/visibleItems)

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

### Getting item metrics

[`index(of:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/index(of:))

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

[`level(of:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/level(of:))

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

[`parent(of:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/parent(of:))

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

[`contains(_:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/contains(_:))

Indicates whether the section snapshot contains the specified item.

[`isVisible(_:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/isVisible(_:))

Indicates whether the specified item is currently visible onscreen.

### Inserting items

[`insert(_:after:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/insert(_:after:)-9v9c7)

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

[`insert(_:after:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/insert(_:after:)-4it9s)

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

[`insert(_:before:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/insert(_:before:)-5o91y)

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

[`insert(_:before:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/insert(_:before:)-bsrn)

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

### Removing items

[`delete(_:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/delete(_:))

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

[`deleteAll()`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/deleteAll())

Deletes all of the items from the section snapshot.

### Replacing items

[`replace(childrenOf:using:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/replace(childrenOf:using:))

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

### Expanding and collapsing items

[`isExpanded(_:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/isExpanded(_:))

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

[`expand(_:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/expand(_:))

Expands the specified items in the section snapshot.

[`collapse(_:)`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/collapse(_:))

Collapses the specified items in the section snapshot.

### Debugging section snapshots

[`visualDescription()`](/documentation/UIKit/NSDiffableDataSourceSectionSnapshot-swift.struct/visualDescription())

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

### Supporting bridging

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

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



---

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)