Swift 4 main thread warning
Opened this issue · 1 comments
Deleted user commented
Main thread warning in this code.
/// You can change insertion/deletion animations like this! Fade works well.
/// So does Top/Bottom. Left/Right/Middle are a little weird, but hey, do your thing.
public var insertionAnimation = UITableViewRowAnimation.automatic, deletionAnimation = UITableViewRowAnimation.automatic
override fileprivate func processChanges(newState: SectionedValues<Section, Value>, diff: [SectionedDiffStep<Section, Value>]) {
guard let tableView = self.tableView else { return }
tableView.beginUpdates()
self._sectionedValues = newState
for result in diff {
switch result {
case let .delete(section, row, _): tableView.deleteRows(at: [IndexPath(row: row, section: section)], with: self.deletionAnimation)
case let .insert(section, row, _): tableView.insertRows(at: [IndexPath(row: row, section: section)], with: self.insertionAnimation)
case let .sectionDelete(section, _): tableView.deleteSections(IndexSet(integer: section), with: self.deletionAnimation)
case let .sectionInsert(section, _): tableView.insertSections(IndexSet(integer: section), with: self.insertionAnimation)
}
}
tableView.endUpdates()
}
}
jflinter commented
Yes, changing the rows
or sectionedValues
property on a DiffCalculator must be done on the main thread.