Below is a small layer for preparing NSDiffableDataSourceSnapshot for a catalog screen. After a recent refactor, the section list started behaving inconsistently: some updates are not reflected in the snapshot, and some items end up in the wrong section.
NSDiffableDataSourceSnapshot<LibrarySection, LibraryItem> from an array of Shelf.isArchived == false should be included in the snapshot.genre of its shelf.genre, they must be merged into one section.SnapshotFactory.makeSnapshot(from:) in two scenarios:
Sample data for manual verification:
let shelves = [
Shelf(
genre: "Sci-Fi",
books: [
Book(id: "b1", title: "Dune", isArchived: false),
Book(id: "b2", title: "Foundation", isArchived: true)
]
),
Shelf(
genre: "Fantasy",
books: [
Book(id: "b3", title: "Hobbit", isArchived: false)
]
),
Shelf(
genre: "Sci-Fi",
books: [
Book(id: "b4", title: "Hyperion", isArchived: false)
]
)
]
Swift 6Swift language mode 6iOS 18 SDKUIKitSnapshotFactory.makeSnapshot(from:)@MainActor is not required, there is no asyncFoundation and UIKitNSDiffableDataSourceSnapshot<LibrarySection, LibraryItem> from UIKit is usedUse line comments to explain the problem, its impact, the fix and how to test it.