From 0ab01fcb1a5dc68361abcfd6604a1ca890030f5a Mon Sep 17 00:00:00 2001 From: Stephen Date: Mon, 15 Jul 2024 19:11:28 +1000 Subject: [PATCH] optimise cell registration --- .../DTTableViewManager/TableViewFactory.swift | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Sources/DTTableViewManager/TableViewFactory.swift b/Sources/DTTableViewManager/TableViewFactory.swift index ebcb495..ac3d938 100644 --- a/Sources/DTTableViewManager/TableViewFactory.swift +++ b/Sources/DTTableViewManager/TableViewFactory.swift @@ -109,13 +109,15 @@ final class TableViewFactory if let cellReuseIdentifier = cell.reuseIdentifier, cellReuseIdentifier != mapping.reuseIdentifier { anomalyHandler?.reportAnomaly(.differentCellReuseIdentifier(mappingReuseIdentifier: mapping.reuseIdentifier, cellReuseIdentifier: cellReuseIdentifier)) } + mappings.append(mapping) + verifyCellInstance(cell, withReuseIdentifier: mapping.reuseIdentifier) + return + } + if let xibName = mapping.xibName, UINib.nibExists(withNibName: xibName, inBundle: mapping.bundle) { + let nib = UINib(nibName: xibName, bundle: mapping.bundle) + tableView.register(nib, forCellReuseIdentifier: mapping.reuseIdentifier) } else { - if let xibName = mapping.xibName, UINib.nibExists(withNibName: xibName, inBundle: mapping.bundle) { - let nib = UINib(nibName: xibName, bundle: mapping.bundle) - tableView.register(nib, forCellReuseIdentifier: mapping.reuseIdentifier) - } else { - tableView.register(Cell.self, forCellReuseIdentifier: mapping.reuseIdentifier) - } + tableView.register(Cell.self, forCellReuseIdentifier: mapping.reuseIdentifier) } mappings.append(mapping) verifyCell(Cell.self, nibName: mapping.xibName, withReuseIdentifier: mapping.reuseIdentifier, in: mapping.bundle) @@ -145,6 +147,13 @@ final class TableViewFactory anomalyHandler?.reportAnomaly(.differentCellReuseIdentifier(mappingReuseIdentifier: reuseIdentifier, cellReuseIdentifier: cellReuseIdentifier)) } } + + func verifyCellInstance(_ cell: UITableViewCell, + withReuseIdentifier reuseIdentifier: String) { + if let cellReuseIdentifier = cell.reuseIdentifier, cellReuseIdentifier != reuseIdentifier { + anomalyHandler?.reportAnomaly(.differentCellReuseIdentifier(mappingReuseIdentifier: reuseIdentifier, cellReuseIdentifier: cellReuseIdentifier)) + } + } func verifyHeaderFooterView(_ view: View.Type, nibName: String?, in bundle: Bundle) { var view = View(frame: .zero)