name: uikit-collections description: Use when building or reviewing UITableView, UICollectionView, diffable data sources, compositional layout, or cell registration.
UIKit Collections
Review and write UITableView and UICollectionView code for correct data source management, modern cell registration, and compositional layouts.
Responsibility
Owns: UITableView, UICollectionView, UITableViewDiffableDataSource, UICollectionViewDiffableDataSource, NSDiffableDataSourceSnapshot, NSDiffableDataSourceSectionSnapshot, UICollectionViewCompositionalLayout, NSCollectionLayoutSection/Group/Item, UICollectionView.CellRegistration, UITableView.CellRegistration, supplementary views, self-sizing cells, swipe actions, prefetching.
Does NOT own: SwiftUI List/LazyVGrid (swiftui-patterns skill), Core Data fetch results controllers (core-data skill), view controller lifecycle (uikit-fundamentals skill).
Core Principles
- Diffable data sources are the default. Never use the legacy
numberOfRows/cellForRowpattern in new code. Diffable data sources eliminate index-out-of-range crashes. - Cell registration over
register(_:forCellReuseIdentifier:). UseUICollectionView.CellRegistration/UITableView.CellRegistrationfor type-safe cell configuration. - Compositional layout for collections. Use
NSCollectionLayoutSectionwithNSCollectionLayoutGroupandNSCollectionLayoutItem— neverUICollectionViewFlowLayoutin new code. - Section snapshots for hierarchy. Use
NSDiffableDataSourceSectionSnapshotfor expandable/collapsible outlines. - Apply snapshots on the main queue. Always call
apply(_:animatingDifferences:)from the main thread. - Self-sizing cells. Set
estimatedItemSizeto.automaticor provide estimated dimensions. Ensure cells have unambiguous height constraints.
References
references/uikit-collections-patterns.md— Diffable data sources, compositional layout, cell registration