From 4092a9ba55c0cd2d6f95c72d2f92b0c344b1dcb4 Mon Sep 17 00:00:00 2001 From: relikd Date: Wed, 13 May 2020 21:55:02 +0200 Subject: [PATCH] Fix tableview access on main thread --- main/Extensions/TableView.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main/Extensions/TableView.swift b/main/Extensions/TableView.swift index b199bb4..5aba71e 100644 --- a/main/Extensions/TableView.swift +++ b/main/Extensions/TableView.swift @@ -103,9 +103,14 @@ extension IncrementalDataSourceUpdate { dataSource.insert(obj, at: to) if shouldLiveUpdateIncrementalDataSource() { DispatchQueue.main.sync { - let cell = tableView.cellForRow(at: IndexPath(row: from)) - cell?.detailTextLabel?.text = obj.detailCellText - tableView.safeMoveRow(from, to: to) + if tableView.isFrontmost { + let source = IndexPath(row: from) + let cell = tableView.cellForRow(at: source) + cell?.detailTextLabel?.text = obj.detailCellText + tableView.moveRow(at: source, to: IndexPath(row: to)) + } else { + tableView.reloadData() + } } } didUpdateIncrementalDataSource(.Move, row: from, moveTo: to)