Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VIPER Arch as example #4

Merged
merged 2 commits into from Oct 18, 2021
Merged

Add VIPER Arch as example #4

merged 2 commits into from Oct 18, 2021

Conversation

specktro
Copy link
Owner

Summary

The VIPER pattern is a solution with steroids for this simple example but you can review the different layers an their function and this is thanks to the protocols or module skeleton.

// MARK: MessageViewProtocol
protocol MessageViewProtocol: UIViewController {
  var presenter: MessagePresenterProtocol? { get set }
  
  // Output
  func show(_ message: String)
}

// MARK: MessagePresenterProtocol protocol
protocol MessagePresenterProtocol: AnyObject {
  var view: MessageViewProtocol? { get set }
  var interactor: MessageInteractorProtocol? { get set }
  
  // Input
  func askMessage()
  
  // Output
  func retrieve(message: String)
}

// MARK: MessageInteractorProtocol protocol
protocol MessageInteractorProtocol: AnyObject {
  var presenter: MessagePresenterProtocol? { get set }
  var person: Person? { get set }
  
  // Input
  func prepareMessage()
}

And with the SharedViewController class our view was pretty simple:

// MARK: MessageView class
final class MessageView: SharedViewController, MessageViewProtocol {
  // MARK: - Properties
  var presenter: MessagePresenterProtocol?
  
  // MARK: - SharedViewController method
  override func didTapButton(_ button: UIButton) { ... }
  
  // MARK: - MessageViewProtocol
  func show(_ message: String) { ... }
}

and this ir our final module's implementation

// MARK: - VIPER Architecture
let view: MessageViewProtocol = MessageView()
let presenter: MessagePresenterProtocol = MessagePresenter()
let interactor: MessageInteractorProtocol = MessageInteractor()
view.presenter = presenter
presenter.view = view
presenter.interactor = interactor
interactor.presenter = presenter
interactor.person = model

@specktro specktro self-assigned this Oct 17, 2021
@specktro specktro merged commit f1bad50 into master Oct 18, 2021
@specktro specktro deleted the feat/specktro/viper_module branch October 18, 2021 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant