Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.