Created
September 20, 2017 17:33
-
-
Save DejanEnspyra/404621db838ed0f3700a459c2c3dc5cf to your computer and use it in GitHub Desktop.
Clean Swift - Presenter Component
This file contains hidden or 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
| 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