Skip to content

Instantly share code, notes, and snippets.

@alvaroroyo
Created February 28, 2019 09:53
Show Gist options
  • Save alvaroroyo/88153da2f3d7718981ce99f2b3187e49 to your computer and use it in GitHub Desktop.
Save alvaroroyo/88153da2f3d7718981ce99f2b3187e49 to your computer and use it in GitHub Desktop.
import Foundation
// Protocolo que define los comandos mandados desde la vista al presenter.
protocol PersonsModuleInterface: class {
func updateView()
func showDetailsForPerson(_ person: Person)
}
// Protocolo que define los comandos mandados desde el interactor al presenter.
protocol PersonsInteractorOutput: class {
func personsFetched(_ persons: [Person])
}
class PersonsPresenter: NSObject, PersonsInteractorOutput, PersonsModuleInterface {
// Referencia a la vista (weak para evitar un retain cycle)
weak var view: PersonsViewInterface!
// Referencia a la interfaz del interactor
var interactor: PersonsInteractorInput!
// Referencia al router
var wireframe: PersonsWireframe!
// MARK: PersonsModuleInterface
func updateView() {
self.interactor.fetchPersons()
}
func showDetailsForPerson(_ person: Person) {
self.wireframe.presentDetailsInterfaceForPerson(person)
}
// MARK: PersonsInteractorOutput
func personsFetched(_ persons: [Person]) {
if persons.count > 0 {
self.view.showPersonsData(persons)
} else {
self.view.showNoContentScreen()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment