Created
June 12, 2019 18:15
-
-
Save shabib87/a15423badc5640fe6ffdf9a1e4218e53 to your computer and use it in GitHub Desktop.
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