Created
October 22, 2017 16:37
-
-
Save mendesbarreto/6c10bcf06217ce5ee76b251ebd1d0274 to your computer and use it in GitHub Desktop.
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
//: A UIKit based Playground for presenting user interface | |
import UIKit | |
import PlaygroundSupport | |
protocol ListGroceriesPresenter { | |
func show(groceries: [Int]) | |
func show(grocery: Int) | |
func showEmptyView() | |
} | |
final class ListGroceriesUserCase { | |
private let presenter: ListGroceriesPresenter | |
init(presenter: ListGroceriesPresenter) { | |
self.presenter = presenter | |
} | |
func list(groceries: [Int]) { | |
if groceries.count > 1 { | |
presenter.show(groceries: groceries) | |
} if let grocery = groceries.first { | |
presenter.show(grocery: grocery) | |
} else { | |
presenter.showEmptyView() | |
} | |
} | |
} | |
final class GroceryListView: UIView, ListGroceriesPresenter { | |
init() {} | |
func show(groceries: [Int]) { | |
print("Olha estou apresentando uma listagem") | |
} | |
func show(grocery: Int) { | |
print("Olha estou apresentando um unico item") | |
} | |
func showEmptyView() { | |
print("Olha estou apresentando nada") | |
} | |
} | |
protocol GroceryGateway { | |
func getGroceryList(onSucess: ([Int]) -> ()) | |
} | |
class GroceryListController { | |
private var mainView: GroceryListView = GroceryListView() | |
private let groceryGateway: GroceryGateway | |
init(groceryGateway: GroceryGateway) { | |
self.groceryGateway = groceryGateway | |
} | |
func carregarListagem() { | |
let listGroceryUseCase = ListGroceriesUserCase(presenter: mainView) | |
groceryGateway.getGroceryList(onSucess: { groceries in | |
listGroceryUseCase.list(groceries: groceries) | |
}) | |
} | |
} | |
// Present the view controller in the Live View window | |
PlaygroundPage.current.liveView = MyViewController() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment