13. View/
ViewController
- Listen to user action
- Call presenter to react to user action
- Display view as per ViewModel
- Contain UIKit related codes
14. - Update/Retrieve data entities via interactorPresenter
- Listen/react to user action
- Transform data entities into view model
(simple data structure for displaying)
- Synchronise view displaying/navigating
15. - Retrieve data entity from
services
- Update data modelInteractor
- A single business use case
- Integrate data
16. - Navigate to the destination
(handle transition)
- Pass data to destinationRouter
- Locate destination
17. VIPER is Great
Good division of responsibilities
Less codes on each class
Make presentation layer more testable
Presenter/Interactor are independent of any UI
Presenter/Interactor contains pure logics
18. Cons of VIPER
Many files, hard to set up
Not easy to identify use case
Complex controls among view/presenter/
interactor
20. Responsibilities of
Presenter
- Receive and handle user actions from View
- Coordinate all the interactors(business use cases)
- Synchronize presentation and navigations
21. Solution by Raymond Law
Clean VIP cycle
Pass UI events
Fetch/Update entities from data model
Pass entity entities
& view state
Maintain data/state
Transform entity
into view models
Listen to UI events
Display view model
Pass view model
31. Router(2)
Navigate to names input view
func navigateToNameInputs() {
// Locate destination
// Pass data entity to data store of destination
let destinationVC = segue.destination
let profile = self?.dataStore?.profile
destinationVC.router.datastore.profile = profile
// Perform navigation
performSegue(identifier: "RegisterNameInputsSegue")
}
33. Clean VIP is Greater
than VIPER
Better responsibility division
Unidirectional control flow
Low dependency(simple interactions) among
components
Dramatically simply debugging
Better testability
34. Some tips
VIP stack can be set up by templates
No UIKit in presenter and interactor
UITableView datasource/delegate stays in
ViewController
Don’t pass data entity to view controller
Set up the complete stack even view is simple