diff options
author | Nicholas Tay <nick@windblume.net> | 2022-07-17 02:13:04 +1000 |
---|---|---|
committer | Nicholas Tay <nick@windblume.net> | 2022-07-17 02:13:16 +1000 |
commit | 1adbed9f8b94521befd237c14d36325a55037a41 (patch) | |
tree | 91d81b4740514083010c72f5f0559283ccd849fa /foray/Scenes | |
parent | daee1f1b5c739f42ba54a1ebbb9655f5034e315f (diff) | |
download | forayios-1adbed9f8b94521befd237c14d36325a55037a41.tar.gz forayios-1adbed9f8b94521befd237c14d36325a55037a41.tar.bz2 forayios-1adbed9f8b94521befd237c14d36325a55037a41.zip |
Experiment with async/await
Note that URLSession async only works >=iOS 15. I changed the target for
now, but may mess with continuations.
Diffstat (limited to '')
-rw-r--r-- | foray/Scenes/ForayTableViewController.swift | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/foray/Scenes/ForayTableViewController.swift b/foray/Scenes/ForayTableViewController.swift index a29088c..849553c 100644 --- a/foray/Scenes/ForayTableViewController.swift +++ b/foray/Scenes/ForayTableViewController.swift @@ -42,21 +42,25 @@ class ForayTableViewController: UITableViewController, Coordinated { self.refreshControl?.addTarget(self, action: #selector(doRefresh), for: UIControl.Event.valueChanged) } - @objc func doRefresh(sender: AnyObject) { + @objc + func doRefresh(sender: AnyObject) { reloadApiData() } func reloadApiData() { - presenter.fetch { [weak self] (data: [PenguinItemViewModel]) in - guard let self = self else { return } - - let groups = Dictionary(grouping: data) { $0.year } + Task(priority: .medium) { [weak self] in + let models = await self?.presenter.fetch() + + guard let self = self, + let models = models else { return } + + let groups = Dictionary(grouping: models) { $0.year } self.sections = groups.map { (key, values) in return YearSection(year: key, items: values) } // Sort the sections from oldest year to newest self.sections.sort { (lhs, rhs) in lhs.year < rhs.year } - + self.tableView.reloadData() self.refreshControl?.endRefreshing() self.coordinator?.hideLoading() |