Skip to content

Instantly share code, notes, and snippets.

@DejanEnspyra
Created September 20, 2017 17:33
Show Gist options
  • Select an option

  • Save DejanEnspyra/404621db838ed0f3700a459c2c3dc5cf to your computer and use it in GitHub Desktop.

Select an option

Save DejanEnspyra/404621db838ed0f3700a459c2c3dc5cf to your computer and use it in GitHub Desktop.
Clean Swift - Presenter Component
import UIKit
protocol TestPresenterInput
{
func presentFetchResults(response: TestModel.Fetch.Response);
}
protocol TestPresenterOutput: class
{
func successFetchedItems(viewModel: TestModel.Fetch.ViewModel)
func errorFetchingItems(viewModel: TestModel.Fetch.ViewModel)
}
class TestPresenter: TestPresenterInput {
weak var output: TestPresenterOutput!
// MARK: - Presentation logic
func presentFetchResults(response: TestModel.Fetch.Response) {
// NOTE: Format the response from the Interactor and pass the result back to the View Controller
let viewModel = TestModel.Fetch.ViewModel(name: response.testObj?.name, date: response.testObj?.date, desc: response.testObj?.desc, isError: response.isError, message: response.message)
if viewModel.isError{
if let output = self.output {
output.errorFetchingItems(viewModel: viewModel)
}
}else{
if let output = self.output {
output.successFetchedItems(viewModel: viewModel)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment