Slalom Build
Published in

Slalom Build

Clean Architecture For iOS Development Using The VIPER Pattern

Photo by Zachary Young on Unsplash

The Usual Suspect

  • Model: The application’s data and logic that manipulates that data.
  • View: The User Interface that the user manipulates.
  • Controller: Controls the logic between the Model and the View.

What is VIPER?

  • View: Displays information from the Presenter and sends user interactions back to the Presenter.
  • Interactor: Retrieves Entities and contains the business logic for a particular use case. They are view agnostic and can be consumed by one or many Presenters.
  • Presenter: Handles preparing content for the display and intercepting user interactions.
  • Entity: Simple data model objects.
  • Router: Handles navigation logic for which screens should appear and when.

The Flow of VIPER

Implementing VIPER

Entity

Interactor

Presenter

Router

View

Testing With VIPER

The Benefits of VIPER

  • Ease of testing: Due to the loosely coupled nature of the VIPER pattern, adding unit tests to every object is simple compared to other patterns.
  • Handles large teams: The project that I used VIPER on had roughly 15 developers. Because of the separation of modules within the pattern, developers can easily work on different parts of the app without stepping on each other’s toes. Using VIPER also helps to reduce merge conflicts.
  • Ease of development: Once the project is fully set up on VIPER, it becomes easier to add a new feature to a module. If you need a new way to sort something, you can add a new method in the Presenter. Developers can couple the VIPER pattern with Dependency Injection to add new features quickly and easily.

The Negatives of VIPER

  • Too much boilerplate code: As you can see in the examples above, a lot of template code needs to be created to create a simple application. This can slow down development in the beginning and add unneeded complexity. The increase of files can also add to the compile time.
  • High learning curve: Due to the increase complexity of VIPER over MVC, the team might need more discussion and training on to properly implement the pattern across their application.
  • Full buy-in: In my experience, the whole project needs to use the VIPER pattern. VIPER does not play nicely with Massive-View-Controllers, partially implemented VIPER modules, third party Cocoapods that do not use VIPER, and even Apple’s own frameworks. When using VIPER with existing code or new frameworks, extra work is required to ensure code compatibility.

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Edward Groberski

Senior Engineer for Slalom Build focusing on native iOS and native Android solutions.