Search code examples
iosarchitectureseparation-of-concerns

Implementing master-detail view using a view model and layer separation


So I read about the VIPER architecture and I was wondering, how you would implement a master-detail view combination using the proposed layer separation between View, View Model, Presenter and View Controller Routing?

Let's say I want to display some contacts. I have the ContactsListViewModel with its properties name, photo and maybe some detail text. This is known to the ContactsListPresenter and ContactsListViewController.

Now I select a contact in my table view, the view controller tells this to the presenter and the presenter tells the wireframe to show the detail view for ... what?

The view model that is known to the List module does not contain enough information to be displayed in detail (like further notes, call list, whatsoever …).

In this case, should there be a view model that can be used for both list and detail view? Would that be a violation of separation of concerns?


Solution

  • As I understand you have 2 options -

    1. Pass a model that includes all the data you need to the Contact List View controller. By that you will have all the data you need. - I personally think its ok in some circumstances, even though it's a bit wasteful.
    2. Pass to the wireframe of the detail view the id of the contact. Then in the loading part of the viewcontroller load through the presnter and then interactor the full data of the contact, then display it.