Building iOS App With VIPER Architecture

Authors
Building iOS App With VIPER Architecture

VIPER is an iOS architecture that stands for View, Interactor, Presenter, Entity, and Router. It is based on the Single Responsibility Principle, which leads to a clean architecture.

This article is about the iOS VIPER architecture. We will go through the following three points.

  • What is VIPER architecture?
  • Building an iOS application with VIPER architecture.
  • Advantages of VIPER architecture.

Following a standard architecture is important as it decouples the code for reusability and testability. It divides the application components based on its role, called separation of concern. (For the Android counterpart, see MVVM Architecture in Android.)

So, let’s explore the VIPER architecture for iOS.

I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.

I teach AI and Machine Learning, and Android at Outcome School.

Join Outcome School and get a high-paying tech job:

Let's get started.

What is VIPER architecture?

VIPER is a backronym for View, Interactor, Presenter, Entity, and Router.

This architecture is based on Single Responsibility Principle which leads to a clean architecture.

  • View: The responsibility of the view is to send the user actions to the presenter and shows whatever the presenter tells it.
  • Interactor: This is the backbone of an application as it contains the business logic.
  • Presenter: Its responsibility is to get the data from the interactor on user actions and after getting data from the interactor, it sends it to the view to show it. It also asks the router/wireframe for navigation.
  • Entity: It contains basic model objects used by the Interactor.
  • Router: It has all navigation logic for describing which screens are to be shown when. It is normally written as a wireframe.

Blueprint of VIPER architecture

viper architecture blueprint

Viper architecture is used for building large projects, but for the sake of understanding, I have created a very simple app to describe it properly.

A quick note for you

No matter which tech domain you work in, get familiar with these topics:

  • LLM
  • RAG
  • MCP
  • Agent
  • Fine-tuning
  • Quantization

We put it all together in one video:

AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization

No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.

Now, let's get back to the topic.

Building iOS application with VIPER architecture

I have created a detailed sample app using VIPER architecture for iOS.

Here is the link to the sample app.

Let’s see the project structure properly for better understanding.

project structure ios viper architecture

The application consists of the three screens:

  • Launch Screen: This is a usual launch screen. So there is nothing to describe here.
  • PostListView Screen: This PostListView tells the presenter to get the post list. Then, the presenter contacts the interactor for the relevant data. The interactor checks the availability of data in the local database, if the data is present it returns to the presenter and the presenter to the view. If the data is not present in the local database, it makes the network call to get the data and return it to the presenter and also saves the data in the local database(CoreData).
  • PostDetailView Screen: When the user clicks on any of the post presented on the PostListView, the PostListPresenter ask the router (PostListWireFrame) to open the PostDetailView. The detail of the selected post is shown on this screen.

And most of the communications between the different classes happens via protocols defined in the project.

The best way to understand it completely is by checking the code and by implementing it. Just clone the project, build and run.

Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.

Advantages of VIPER architecture

  • It decouples the code for reusability and testability.
  • It divides the application components based on its role, called separation of concern.
  • Adding new features is easier.
  • It’s easier to write automated tests since your UI logic is separated from the business logic.

Frequently Asked Questions

Where does the business logic live in VIPER?

The business logic lives in the Interactor. It is the backbone of the application. The Presenter gets the data from the Interactor on user actions, and the Interactor uses the basic model objects from the Entity.

Does the View talk to the Interactor directly in VIPER?

No. The View only sends the user actions to the Presenter and shows whatever the Presenter tells it. The Presenter gets the data from the Interactor and then sends it to the View to show it.

Who handles navigation in VIPER?

The Router handles navigation. It has all the navigation logic that describes which screens are shown when, and it is normally written as a wireframe. The Presenter asks the Router when it needs to open a new screen.

What kind of projects is VIPER used for?

VIPER is used for building large projects. It decouples the code for reusability and testability, and makes adding new features easier. For the sake of understanding, a very simple app can also be built with VIPER, like the sample app with three screens.

That's it for now.

Thanks

Amit Shekhar
Founder @ Outcome School

You can connect with me on:

Follow Outcome School on:

Read all of our high-quality blogs here.

Tags