VIP /CLEAN SWIFT DESIGN PATTERN (SWIFT-iOS)

WHY WE NEED DESIGN ARCHITETURES?

Serra Saracoglu
4 min readAug 13, 2021

--

Design patterns are the solutions for the problems which developers face during coding and it everyone can find out their solutions. We have many of them out there as technology grows and we find out new problems our way to approach to them is also changing.

WHY VIP?

As apps becoming complex and bigger by the time developers needs and preferences has changed as we mentioned above and VIP architecture opened very exciting way to iOS developers for handling complex work .

If many developers work on the same project,

If you have limited time,

If you need easy testing for whole project ,

If you have hard times struggling with many view controllers and feels like impossible to add new feature or debug and fixing it,

it would nice to find out VIP architecture- aka Clean-Swift.

Design architectures also show us a practical way for clean coding as well. They make easier to understand code for developer and even for user which is important duty of clean coding as well.

After explaining why design patterns are important for us we can start to learn about VIP!

HOW TO CREATE VIP

As we understand from it’s name we have three main component for VIP architecture,

First is as you can guess from its’ initial ;

View Controller: Which we see all times of development cycle and main responsible of view controller is interacting with the user.

It has all UI, it will be our starting point for whole story.When you click generate joke button from view controller it will send a request to the interactor for doing some other job and after some user interaction presenter will give route us the thing what we wanted.

Interactor is the second component of our VIP architecture, it is the place where we do all API jobs and calls.You fetch the data exactly here.

And our last component is

Presenter ; It calls view controller by passsing data.

Those were our main three components but additionally we have some other components such as Worker,Router etc.

To be enlightened about VIP we first may understand scenes. VIP has a lot of scenes and those scenes has VIP cycle under all of them.

For example adding book is a scene, register is a scene or login is a. Scene. It is different for every project and we can have many of them depend on how big and complicated our project is.

scenes

Communication between our components will be done by protocols.

A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to conform to that protocol.

Each our components should have protocols to receive and passing data between them.

So what about the other components like Router and Models?

The Model

  • Decoupled data abstractions.

The Router

  • Extracts this navigation logic out of the view controller.
  • Keeps a weak reference to the source (View Controller).
  • We can use segues with VIP unlike VIPER:)

WHAT ARE THE SOURCES TO LEARN

Amazing one;

https://www.netguru.com/blog/clean-swift-ios-architecture-pattern

Thank you for reading the article, after learning about VIP next step is making a something real to learn it completely and well.

So good luck with it. You can find many templates on GitHub to work on easily and help you to understand the structure well.

Share your project GitHub link under the comments for inspiration for all of us, and all comments and suggestions are welcome.

Have a nice day of coding!

--

--