vendredi 15 novembre 2019

Where to trigger Loading in Clean Architeture Swift

My question is the correct place I should put the code that would trigger a loading to display in my app.

It is correct to do is on view? since it is displaying something on screen, so it fits as a UI logic

class ViewController: UIViewController {
 func fetchData() {
     showLoading()
     interactor?.fetchData()
}

or on interactor? since it's a business logic. something like, everytime a request is made, we should display a loading. View only knows how to construct a loading, not when to display it.

class Interactor {
 func fetchData() {
     presenter?.presentLoading(true)
     worker?.fetchData() { (data) [weak self] in
          presenter?.presentLoading(false)
          self?.presenter?.presentData(data)
     }
}

same question applies to MVVM and MVP.

Aucun commentaire:

Enregistrer un commentaire