Hero list presenter class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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