Skip to content

Instantly share code, notes, and snippets.

@shabib87
Created June 12, 2019 18:15
Show Gist options
  • Save shabib87/a15423badc5640fe6ffdf9a1e4218e53 to your computer and use it in GitHub Desktop.
Save shabib87/a15423badc5640fe6ffdf9a1e4218e53 to your computer and use it in GitHub Desktop.
Hero list presenter class
final class HeroListPresenter: Presenter {
private let service: HeroService
weak private var view : HeroListView?
...
init(service: HeroService) {
self.service = service
}
func attachView(view: HeroListView) {
self.view = view
}
...
func getHeroes() {
self.view?.startLoading()
service.getHeroes { [weak self] heroes in
self?.view?.finishLoading()
if heroes.count > 0 {
let mappedHeroes = heroes.map {
return HeroViewData(hero: $0)
}
self?.heroes.append(contentsOf: mappedHeroes)
self?.view?.reloadHeroList()
} else {
self?.view?.showEmptyListMessage()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment