From 0e69bf53bd0c54ebf361a0934e1ca00fc007e467 Mon Sep 17 00:00:00 2001 From: Christian Gossain Date: Tue, 18 Jul 2017 17:50:01 -0600 Subject: [PATCH] Pass `oldSections` value to `refreshTableSections()` method. Not sure it this was intentional, but the the old sections were not being passed to the `refreshTableSections()` method, preventing the incremental updating behaviour that appears to already be implemented. --- Static/DataSource.swift | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Static/DataSource.swift b/Static/DataSource.swift index dea8305..1331cac 100644 --- a/Static/DataSource.swift +++ b/Static/DataSource.swift @@ -28,7 +28,7 @@ public class DataSource: NSObject { public var sections: [Section] { didSet { assert(Thread.isMainThread, "You must access Static.DataSource from the main thread.") - refresh() + refresh(oldSections: oldValue) } } @@ -72,7 +72,7 @@ public class DataSource: NSObject { guard let indexPath = tableView?.indexPathForRow(at: point) else { return nil } return row(at: indexPath) } - + // MARK: - Private @@ -83,8 +83,8 @@ public class DataSource: NSObject { refresh() } - private func refresh() { - refreshTableSections() + private func refresh(oldSections: [Section] = []) { + refreshTableSections(oldSections: oldSections) refreshRegisteredCells() } @@ -96,7 +96,7 @@ public class DataSource: NSObject { return sections[index] } - + fileprivate func row(at indexPath: IndexPath) -> Row? { if let section = section(at: indexPath.section) { let rows = section.rows @@ -104,14 +104,14 @@ public class DataSource: NSObject { return rows[indexPath.row] } } - + assert(false, "Invalid index path: \(indexPath)") return nil } - - private func refreshTableSections(oldSections: [Section]? = nil) { + + private func refreshTableSections(oldSections: [Section] = []) { guard let tableView = tableView else { return } - guard let oldSections = oldSections else { + if oldSections.isEmpty { tableView.reloadData() return } @@ -120,9 +120,9 @@ public class DataSource: NSObject { let newCount = sections.count let delta = newCount - oldCount let animation = UITableViewRowAnimation.automatic - + tableView.beginUpdates() - + if delta == 0 { tableView.reloadSections(IndexSet(integersIn: 0.. = start..<(start - delta) tableView.deleteSections(IndexSet(integersIn: range), with: animation) } - + // Reload existing sections let commonCount = min(oldCount, newCount) tableView.reloadSections(IndexSet(integersIn: 0..