As an iOS lead, what list standard do you set for new UIKit screens: collection views with diffable data sources, compositional layout and cell registration, or index-path table views?
answer
- one stack for every list shape
- consistency versus churn
- IDs, registrations, reconfigure
- convert when touched
basics
~20 sDefault new screens to UICollectionView with compositional layout, CellRegistration and a diffable data source keyed by stable IDs: one model for lists, grids and carousels. Leave working index-path table screens alone and convert one when it is reworked.
solid answer
~50 sThe judgment is consistency against churn. Since iOS 14 a collection view with a list configuration does what a table does (separators, headers, swipe actions), and compositional layout adds grids and orthogonal carousels, so one stack covers every list shape. `CellRegistration` ties a cell type to an item type with no string identifiers, a diffable data source removes count bookkeeping, and content configurations replace the to-be-deprecated `textLabel`; all of it is available on an iOS 17 baseline. The costs: each apply diffs in O(n), identifiers need a model lookup, and engineers who learned tables need time. My rule: new list screens use the modern stack; identifiers are stable IDs, never whole models; registrations are created once; content changes use `reconfigureItems(_:)`. A plain settings table may stay `UITableView` with `UITableViewDiffableDataSource`, and existing index-path screens convert only when they are reworked anyway.
go deeper
Recall the two families of list API, index-path and diffable, and that collection views can show table-style lists since iOS 14.
Explain what each piece of the modern stack replaces: registrations for string identifiers, snapshots for batch updates, configurations for textLabel.
Know the failure modes the standard must guard: duplicate identifiers, registrations in the provider, model identifiers, swapping the data source.
Own the trade-off: a default for new screens, a conversion policy for old ones, the deviations you allow, and how you will measure that it paid off.
## The decision Every team that still writes UIKit lists ends up with a mix: index-path table views from years ago, a few collection views with flow layouts, and newer screens with diffable data sources. A lead has to decide what **new** screens use and what happens to **old** ones. There is no single right answer; the choice trades consistency and safety against migration cost and familiarity. SwiftUI's `List` is a separate per-screen decision and does not change what the UIKit standard should be. ## The options | Option | Strengths | Costs | |---|---|---| | `UITableView` with index-path methods | familiar, fine for a simple vertical list | string reuse identifiers, manual `performBatchUpdates` bookkeeping, vertical lists only | | `UITableView` with `UITableViewDiffableDataSource` | snapshot diffing on a familiar view | still vertical-only; no cell registration type, so string identifiers remain | | `UICollectionView` with compositional layout, list configuration, `CellRegistration` and a diffable data source | one stack for lists, grids and carousels; typed registration; diffing | an O(n) diff per apply, a model lookup by ID, a learning curve | ## What the default buys - **One mental model for every list shape.** A listings home with a carousel, a grid and a list is one collection view with three sections, not nested scroll views. - **No count mismatches.** The data source computes the changes from a snapshot, so the exception you get when batch-update counts disagree goes away. - **Typed cell setup.** `UICollectionView.CellRegistration` (iOS 14) binds a cell class to an item type and registers itself on first use, removing string identifiers and casts. - **Table features in the list.** `UICollectionLayoutListConfiguration` brings separators, header modes and swipe action providers. - **Clear update tools.** `reconfigureItems(_:)` (iOS 15) updates cells in place; `applySnapshotUsingReloadData(_:)` (iOS 15) resets when you need it. - **Baseline fit.** Everything above shipped by iOS 15, so an iOS 17 deployment target needs no availability checks for it. ## What it costs - **Diff cost.** `apply` is O(n) in the number of items. For typical screens this is negligible; for exceptionally large changes the header suggests skipping the diff with `applySnapshotUsingReloadData(_:)`. - **Indirection.** Items are IDs, so cells look models up in a store; that store becomes something to design and test. - **New failure modes.** Duplicate identifiers raise an exception, a registration made inside the cell provider raises one in iOS 15 and later, and the documentation says not to change a collection view's data source once a diffable one is attached. - **Training and churn.** Rewriting working table screens costs time and risk with little user benefit. ## The rule, written down 1. New list screens use `UICollectionView`, compositional layout (list configuration for plain lists), `CellRegistration` and a diffable data source. 2. Item identifiers are stable model IDs, never whole models and never positions. 3. Registrations are created once, outside the cell provider. 4. Content changes use `reconfigureItems(_:)`; `reloadItems(_:)` only when the cell type changes. 5. Cells use content configurations rather than `textLabel` and `imageView`. 6. Configure methods set every field; `prepareForReuse()` holds no content logic. 7. Existing index-path screens are converted only when the screen is reworked for another reason. ## When to deviate - A short, static settings screen may stay a grouped `UITableView`, ideally with `UITableViewDiffableDataSource`. - A screen fed by a Core Data fetched results controller follows that controller's change reporting; how the controller produces snapshots belongs to the Core Data material. - A list whose whole content is replaced at once can apply with `applySnapshotUsingReloadData(_:)` rather than diffing. - Where a team is moving the screen to SwiftUI soon, converting the UIKit list first is wasted work. ## Rolling it out Ship one reference screen that shows the whole pattern, add the rules to the pull request checklist, and measure scrolling on the oldest supported device before and after a conversion rather than assuming the new stack is faster. A small shared helper for the boilerplate (a function that builds the data source from a registration, or a store type that maps IDs to models) keeps screens consistent without hiding UIKit behind a framework of your own. Keep it thin: when the helper grows options for every screen's special case, engineers stop recognising the UIKit types underneath, and the standard turns into a private API that new hires must learn first.
- Where would you deliberately keep UITableView?On short, stable screens such as settings, and on existing table screens that work and are not being reworked. If such a screen is touched, a cheap improvement is `UITableViewDiffableDataSource` plus content configurations without changing the view class.
- How do you check in review that the standard is followed?Look for identifiers that are whole models or positions, registrations created inside the cell provider, `reloadItems(_:)` used for plain content changes, `textLabel` instead of a content configuration, and configure code that sets a field in only one branch. Each has a one-line fix.
- Someone worries that diffing large lists is slow; how do you answer?The documentation states the diff is O(n) in the number of items, which is cheap for typical screens. For an exceptionally large or complete replacement, `applySnapshotUsingReloadData(_:)` skips the diff. Settle it with a measurement on the oldest supported device, not by abandoning the standard.
- UITableView is deprecated, so every table screen must be rewritten now.
- Compositional layout cannot show a table-style list with swipe actions.
- Diffable data sources need iOS 18, so an iOS 17 baseline cannot use them.
- Whole model structs are the best identifiers because the diff then sees every change.
- A list standard is pointless; each engineer should pick an approach per screen.