From 6eb57f5c448dc1ad7a3d4bc3567cdeadad744232 Mon Sep 17 00:00:00 2001 From: Daniel Arantes Loverde Date: Sat, 29 Aug 2026 19:33:59 -0300 Subject: [PATCH] [docs] UIKit.md: Collections & Tables section --- Documentation/UIKit.md | 92 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/Documentation/UIKit.md b/Documentation/UIKit.md index 9bd9df7..696c795 100644 --- a/Documentation/UIKit.md +++ b/Documentation/UIKit.md @@ -606,7 +606,97 @@ UIDevice.current.modelName // "iPhone 16 Pro" ## Collections & Tables - +
+UITableView — typed dequeue, safe indexing, cell animations + +### `func dequeueReusableCell(withClass name: T.Type) -> T` / `…(withClass:for indexPath:) -> T` +Dequeue a cell by its class name as the identifier. **Traps** if the cell isn't registered. + +```swift +let cell = tableView.dequeueReusableCell(withClass: OrderCell.self, for: indexPath) +``` + +### `func dequeueReusableHeaderFooterView(withClass name: T.Type) -> T` +Same, for section header/footer views. + +### `func dequeueCell(indexPath: IndexPath) -> T` +Dequeue using `T.identifier` (`"id" + class name`). + +### `func reloadData(_ completion: @escaping () -> Void)` +`reloadData()` with a callback for when layout settles. + +### `func isValidIndexPath(_:) -> Bool` +Bounds check against the current section/row counts. + +### `func safeScrollToRow(at:at scrollPosition:animated:)` +`scrollToRow` that silently no-ops for an out-of-range index path. + +### `func makeMoveUpWithFadeAnimation(rowHeight:duration:delayFactor:) -> UITableViewCellAnimation` +Build a staggered slide-up + fade-in cell animation closure. + +```swift +let animator = UITableViewAnimator( + animation: tableView.makeMoveUpWithFadeAnimation(rowHeight: 64, duration: 0.35, delayFactor: 0.03) +) + +func tableView(_ t: UITableView, willDisplay cell: UITableViewCell, forRowAt ip: IndexPath) { + animator.animate(cell: cell, at: ip, in: t) +} +``` + +### `typealias UITableViewCellAnimation = (UITableViewCell, IndexPath, UITableView) -> Void` +### `class UITableViewAnimator` +`init(animation:)` + `animate(cell:at:in:)` — runs a cell animation closure. + +### `UITableViewCell.identifier` / `UITableViewCell.prepareDisclosureIndicator()` +`"id" + class name`; and re-tint the disclosure chevron to a template image so it +picks up `tintColor`. + +
+ +
+UICollectionView — setup, counts, safe indexing, carousel layout + +### `static var identifier: String` +`"id" + class name`. + +### `func setupCollectionView(flowLayout: = UICollectionViewFlowLayout(), spacings: = 0, direction: = .horizontal, edgesInset: = .zero, allowMulpleSelection: Bool = false, automaticSize: CGSize? = nil)` +Configure layout spacing/direction/insets, multi-selection, and self-sizing in one call. + +```swift +collectionView.setupCollectionView(spacings: 8, direction: .vertical, + edgesInset: .init(top: 12, left: 16, bottom: 12, right: 16)) +``` + +### `func reloadData(_ completion: @escaping () -> Void)` +Reload with a completion callback. + +### `func numberOfItems() -> Int` +Total items across all sections. + +### `var lastSection: Int` / `var indexPathForLastItem: IndexPath?` / `func indexPathForLastItem(inSection:) -> IndexPath?` +Last section index; index path of the last item overall or in a section. + +### `func isValidIndexPath(_:) -> Bool` / `func safeScrollToItem(at:at scrollPosition:animated:)` +Bounds check; scroll that no-ops on an invalid index path. + +### `enum CollectionViewFlowLayoutSpacingMode` +`.fixed(spacing:)` / `.overlap(visibleOffset:)` — spacing strategy for the carousel layout below. + +### `open class CollectionViewFlowLayout: UICollectionViewFlowLayout` +A centred, paginated "cover-flow" style layout: the centred item is full size, +side items scale and fade. Tunables: `sideItemScale` (0.6), `sideItemAlpha` +(0.6), `sideItemShift` (0), `spacingMode` (`.fixed(40)`). + +```swift +let layout = CollectionViewFlowLayout() +layout.itemSize = CGSize(width: 240, height: 320) +layout.sideItemScale = 0.7 +layout.spacingMode = .overlap(visibleOffset: 30) +collectionView.collectionViewLayout = layout +``` + +
## Media & Components