7.12 · Refreshing diffable cells, outlines and carousel layouts
The three things that surprise people after the first working diffable collection view: why an edited cell does not update, how expandable outlines work, and what an orthogonal section really measures.
Mental model. Identity decides whether anything is redrawn. Same identity with new content updates nothing until you ask; reconfigure reuses the cell, reload recycles it.
Updating cells
Equality, reconfigure and reload.
- An item's title changed but its cell still shows the old text after applying a new snapshot. Why, and what is the difference between reconfigureItems and reloadItems?
A diffable data source compares snapshots by identity (Hashable equality), not by content. When the item's == and hash use only its id, a new snapshot…
Structure and layout
Expandable outlines and carousel sections.
- How do you build an expandable outline with NSDiffableDataSourceSectionSnapshot?
A section snapshot models one section as a tree. You append(_:) root items, then append(_:to:) to add children under a parent, and the snapshot tracks… - What does an orthogonally scrolling compositional section measure and scroll, and how does a pinned header behave?
An orthogonalScrollingBehavior section is a horizontal scroller embedded in a vertical collection; the section's groups are laid out along the cross axis, and…
More in UIKit
- 7.1 · Hit testing, the responder chain and gesture recognisers
- 7.2 · UIView and CALayer, frame, bounds and center
- 7.3 · View controller lifecycle, containment, presentation and transitions
- 7.4 · Navigation, tab, split and page controllers
- 7.5 · Compositional layout, diffable data sources, cell reuse and prefetching
- 7.6 · UITableView, still asked and still everywhere
- 7.7 · Trait collections, size classes, safe area, keyboard and appearance
- 7.8 · Keyboard shortcuts, pointer, Apple Pencil and multitasking
- 7.9 · Hosting SwiftUI in UIKit and UIKit in SwiftUI
- 7.10 · Initialisers, stack views, scroll views and modern buttons
- 7.11 · Layout passes, retain cycles and menus
- 7.13 · View-tree exercises and long navigation stacks