Understanding MVP

We all are using MVC in the beginning because it is easy, but MVP architecture is not that difficult to understand and implement in iOS project. Currently, I am using the MVP architecture in my latest project and I come to know many advantages of it.

To begin with, the most preponderant advantage of using MVC is that it is scalable. The second significant advantage which is worth mentioning is that if you have different flavours of your application where business logic (presenter) is same, then MVC is the right choice.

A good example here is:-

MVP folder structure consist of model, view, protocols, presenter, xib, service classes.

  1. Model class consist of all the properties which hold the data
  2. View class consist of all the UI elements which are visible to user. Separate xib for each view
  3. Protocol class consist of methods which need to implement by view class and presenter class
  4. Presenter class consist of business logic
  5. Service class consist of api interaction methods

  1. Assign the custom view class in the storyboard or programatically initilize it in the super controller.
  2. In the view class, initiate the presenter
  3. In the presenter, call the webservice or any initial business logic calculations
  4. After receiving data from server, call method of view class to update UI
  5. All the methods (presenter:- attachView(), detachView() and view class:-
    loadSupportDataInUI(), showErrorLoadingView() ) must be defined in protocol class.

Now, if your need to theming your application by keeping all the business logic same, then re-use the presenter class and update the view classes only.

Popular posts from this blog

Play youtube video in iOS app

Disabling print for Production In Swift Project