4

I have a problem dealing with the return of some info from a module that has been presented by another module. In my case I have two modules, Map and Search. The MapView notifies that it wants to search an address, so the MapPresenter begins the actions to show the Search module (its view is shown modally). Inside the Search module I make a text search, obtain the results, show it and select one. That selection has to be returned to the Map module. How can I achieve that without breaking boundaries?

Taking into account, and please correct me if I'm wrong, that the communication between modules has to be achieved only via routing (not "jumping" between modules with notifications, completion blocks and so on), I implemented this scenario:

viper-flow-chart (Sorry, maybe a sequence diagram would be better)

MapWireframe implements the regular interface but also another one I called MapModuleInput, so when I begin the search action (blue) I pass to the SearchWireframe the MapWireframe implementing that interface.

After that, in the red flow, in the SearchView I begin the search case, it obtains the results from the interactor, etc. After that the results are presented and the user selects one (green), so the selected result is returned to the map via the MapModuleInput interface.

So, is that correct?

Thank you!

emenegro
  • 6,510
  • 9
  • 42
  • 64
  • Did you get an answer for your question? I have a similar one http://stackoverflow.com/questions/28892833/clean-architecture-robert-martin-how-to-connect-use-cases – Rodrigo Ruiz Mar 07 '15 at 03:09
  • 1
    I think the problem is that VIPER came from Robert Martin's Clean Architecture and he comes from a Web (Rails) background, so he doesn't think much about state. Which is mainly my question, where should the state (search result selected, in case you don't dismiss right away, but still want to update the MapView behind) be stored, how should the different modules communicate, should it be through the Wireframe, or through the Database like @PaNaVTEC suggested, or through the Presenters communicating with each other like here https://github.com/objcio/issue-13-viper-swift. – Rodrigo Ruiz Mar 07 '15 at 03:12

1 Answers1

0

If i understood correctly you have a "module" with the search, it searches with the search interactor, retrieves some POIs and the returns this result to the search presenter. You have a problem that you can avoid, instead of retrieving results in SearchPresenter, just communicate to the map and send the query, then use the SearchInteractor in MapView, now you don't have to send objects between modules. If you need to do this in the way you painted in the diagram use a DataSource like Core Data to persist huge objets and retrieve it later in the other "module".

PaNaVTEC
  • 2,459
  • 1
  • 21
  • 36