aboutsummaryrefslogtreecommitdiff
path: root/foray/Presenters
diff options
context:
space:
mode:
authorNicholas Tay <nick@windblume.net>2022-03-25 09:52:06 +1100
committerNicholas Tay <nick@windblume.net>2022-03-25 09:52:06 +1100
commit07a6eb8325d3b67d998003d3fe5ab34e1a72f106 (patch)
treed0399896aa38f7deffe5e011e6dd4bf881b25b99 /foray/Presenters
parentfe60f99848498a932d9113f8e516700a836dd1cd (diff)
downloadforayios-07a6eb8325d3b67d998003d3fe5ab34e1a72f106.tar.gz
forayios-07a6eb8325d3b67d998003d3fe5ab34e1a72f106.tar.bz2
forayios-07a6eb8325d3b67d998003d3fe5ab34e1a72f106.zip
getData -> fetch, try threading, move logic around
Diffstat (limited to '')
-rw-r--r--foray/Presenters/PenguinItemPresenter.swift16
1 files changed, 10 insertions, 6 deletions
diff --git a/foray/Presenters/PenguinItemPresenter.swift b/foray/Presenters/PenguinItemPresenter.swift
index 0420825..2f3730f 100644
--- a/foray/Presenters/PenguinItemPresenter.swift
+++ b/foray/Presenters/PenguinItemPresenter.swift
@@ -8,12 +8,16 @@
import Foundation
class PenguinItemPresenter {
- func getData(onComplete: @escaping ([PenguinItemViewModel]) -> ()) {
- ForayNetworkManager.shared.get(
- url: "https://users.windblume.net/~nick/upload/dummy.json",
- onComplete: { (apiItems: [PenguinItemModel]) in
- onComplete(self.transform(models: apiItems))
- })
+ func fetch(receiver: @escaping ([PenguinItemViewModel]) -> ()) {
+ ForayNetworkManager.shared
+ .fetch(url: "https://users.windblume.net/~nick/upload/dummy.json") { (apiItems: [PenguinItemModel]) in
+ // Callback to main thread here
+ // There probably is a nicer way to do it, but we will DispatchQueue it back
+ // from the Presenter-level for now (main thread from VC onwards)
+ DispatchQueue.main.async {
+ receiver(self.transform(models: apiItems))
+ }
+ }
}
func transform(models: [PenguinItemModel]) -> [PenguinItemViewModel] {