Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What comes after VIPER? by Steve Powell

iOSLove
April 01, 2016

What comes after VIPER? by Steve Powell

Steve Powell @s-powell, a robotics nerd turned iOS developer discusses how iOS architecture can be improved if we consider VIPER as a starting point.

You can watch the full presentation here: https://youtu.be/B30rHcVXfO8

iOSLove

April 01, 2016
Tweet

Other Decks in Technology

Transcript

  1. MVC

  2. MVC - Model: contains data - View: displays data -

    Controller: does everything else
  3. MVC

  4. MVC

  5. MVVM - Model: contains data - View: displays data -

    View Model: presentation logic - (Controller: still does everything else)
  6. VIPER - View: displays data - Entity: contains data -

    Presenter: presentation logic - Interactor: ? - Router: ? _
  7. VIPER - View: displays data - Model: contains data -

    View Model: presentation logic - Interactor: ? - Router: ? _
  8. VIPER - View: displays data - Entity: contains data -

    Presenter: presentation logic - Interactor: business logic - Router: navigation logic _
  9. VIPER - View: displays data - Entity: contains data -

    Presenter: presentation logic - Interactor: business logic - Router: navigation logic - (Data Store: persistence logic)
  10. VIPER - View: displays data - Entity: contains data -

    Presenter: presentation logic - Interactor: business logic - Router: navigation logic - (Data Store: persistence logic) - (Controller: still does everything else)
  11. Interactor - Logic for a module's use cases e.g. logging

    in, signing up, creating a user, resetting a password
  12. to - Presenter: presentation logic - Interactor: business logic -

    Router: navigation logic - Data Store: persistence logic
  13. MVC

  14. Persistence - Logic for in-memory data structures <-> database objects

    - Logic for executing queries on database - Logic for writing to the database
  15. Networking - Logic for creating and formatting network requests -

    Logic for handling network responses - Logic for JSON <-> native types
  16. Data Manager - Logic for when to cache / call

    - Provides model parsers for persistence - Provides formatters for networking
  17. from - Presenter: presentation logic - Interactor: business logic -

    Router: navigation logic - Data Store: persistence logic
  18. to - Router: navigation logic - Wireframe: module logic -

    Presenter: presentation logic - Interactor: business logic - Data Manager: caching logic - Networking: networking logic - Persistence: persistence logic
  19. internal final class SettingsVC: UIViewController { @IBOutlet private weak var

    settingsView: SettingsView! weak var router: Router? } override func viewDidLoad() { super.viewDidLoad() // create components // link components ...
  20. override func viewDidLoad() { super.viewDidLoad() let serializer = Serializer() let

    APIClient = API(authToken: serializer.currentSessionToken) let dataManager = ModelDataManager(serializer: serializer, APIClient: APIClient) let interactor = SettingsInteractor(dataManager: dataManager) dataManager.interactor = interactor let presenter = SettingsPresenter(interactor: interactor) interactor.presenter = presenter settingsView.presenter = presenter presenter.view = settingsView presenter.wireframe = self }
  21. internal final class SettingsVC: UIViewController { @IBOutlet private weak var

    settingsView: SettingsView! weak var router: Router? }
  22. internal protocol SettingsWireframeType {...} internal final class SettingsVC: UIViewController {

    @IBOutlet private weak var settingsView: SettingsView! weak var router: SettingsRouterType? } extension SettingsVC: SettingsWireframeType { ... }
  23. internal protocol AuthInteractor: SignUpInteractor, LoginInteractor { } internal protocol SignUpInteractor

    { func signUp(withEmail email: String, password: String, name: String, completion: Result<Session, NSError> -> Void) } internal protocol LoginInteractor { func login(withEmail email: String, password: String, completion: Result<Session, NSError> -> Void) } internal protocol SignOutInteractor { func signOut(completion: Result<Session, NSError> -> Void) }
  24. to:

  25. override func viewDidLoad() { super.viewDidLoad() let serializer = Serializer() let

    APIClient = API(authToken: serializer.currentSessionToken) let dataManager = ModelDataManager(serializer: serializer, APIClient: APIClient) let interactor = SettingsInteractor(dataManager: dataManager) let presenter = SettingsPresenter(interactor: interactor) settingsView.presenter = presenter settingsView.delegate = self }
  26. - View controllers provide view lifecycle information - Tightly coupled

    to storyboards and XIBs - Remove logic (New wireframe object)
  27. extension SettingsWireframe: Wireframe { var viewController: UIViewController { let serializer

    = Serializer() let APIClient = API(authToken: serializer.currentSessionToken) let dataManager = ModelDataManager(serializer: serializer, APIClient: APIClient) let interactor = AuthInteractor(dataManager: dataManager) let presenter = SettingsPresenter(interactor: interactor) let vc = SettingsViewController(presenter: presenter, delegate: self) return vc } }
  28. → interactor for fetching objects of a type → interactor

    for updating objects of a type → interactor for deleting objects of a type module interactor that glues them together
  29. - one massive router to handle navigation for whole app

    vs - one coordinator for each section