From 98c1057f29783ff68fbdeda7f29568e1e6ebdf58 Mon Sep 17 00:00:00 2001 From: common Date: Thu, 27 Jun 2019 16:26:31 -0400 Subject: [PATCH] Fix memory leak and make sure table view data source and delegate are set before reloading tableview binding data --- .../Table views/Presentables+UITableView.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Presentables/Classes/Table views/Presentables+UITableView.swift b/Presentables/Classes/Table views/Presentables+UITableView.swift index c2c5acc..7fedf20 100644 --- a/Presentables/Classes/Table views/Presentables+UITableView.swift +++ b/Presentables/Classes/Table views/Presentables+UITableView.swift @@ -24,13 +24,16 @@ extension UITableView: PresentableCollectionElement { if Thread.isMainThread { reloadData() } else { - DispatchQueue.main.async { - self.reloadData() + DispatchQueue.main.async { [weak self] in + self?.reloadData() } } } public func bind(withPresentableManager manager: inout PresentableManager) { + dataSource = manager as? UITableViewDataSource + delegate = manager as? UITableViewDelegate + let m = manager manager.bindableData.bind { [weak m] (data) in if let data = m?.data { @@ -47,10 +50,7 @@ extension UITableView: PresentableCollectionElement { manager.needsReloadData = { self.safeReloadData() } - - dataSource = manager as? UITableViewDataSource - delegate = manager as? UITableViewDelegate - + if let manager = manager as? PresentableTableViewDataManager { manager.tableView = self }