VIPER For SwiftUI? Please. No.

Or why you shouldn’t pet that particular snake.

Michael Long
Better Programming
Published in
9 min readJul 16, 2022

--

Photo by Chris Curry on Unsplash

Everyone loves to write about how they’re using their favorite UIKit architecture with SwiftUI. And one of the more prominent design patterns/architectures out there is VIPER.

View-Interactor-Presenter-Entity-Router.

Don’t get me wrong. VIPER is a great software architecture, designed to solve quite a few of the classic and common problems seen when developing and creating applications based on UIKit and UIViewController.

But it’s not the best architecture for SwiftUI. Nor the second best. In fact, it’s one of the worst and in this article I hope to show why.

But before I can do that, we first need to know two things.

  1. What is VIPER?
  2. What problems does it solve?

Let’s dig in.

What is VIPER?

As mentioned above, VIPER is an acronym that stands for View-Interactor-Presenter-Entity-Router.

If you’re here reading this you’re probably already familiar with VIPER. So rather than taking the time to explain each component myself, I’m going to take a shortcut and borrow a bit from a very well-written article on the subject by Mahdi Chtioui.

Here are the components in a VIPER module.

View: The view layer, which is basically the UIViewController and any other view type. This layer contains the UI logic (display, update, animate…) and responsible for intercepting the user’s action and send it to the presenter. Most importantly, it has no business logic.

Interactor: We can think of it as “The Network Manager”: responsible for retrieving data from the services (Network, database, sensors…) when requested by the presenter. The interactor is responsible for managing data from the model layer (note that Model is not part of the VIPER architecture, feel free to implement it or not, but for sure it will make our app more concise).

Presenter: I like to think of it as the motherboard, it connects all layers together. The presenter is the only layer that communicates with the view (The rest of layers communicates with the presenter). Basically, it’s the…

--

--

I write about Apple, Swift, and SwiftUI in particular, and technology in general. I'm also a Lead iOS Engineer at InRhythm, a modern digital consulting firm.