View Presenter and iOS Model (Swift) Architecture

I am exploring the application of the View View Center architecture for a new iOS project. After some reading, I found that this post had a better example. Link to source code here .

At the bottom of the example is assembly code:

// Assembling of MVP let model = Person(firstName: "David", lastName: "Blaine") let view = GreetingViewController() let presenter = GreetingPresenter(view: view, person: model) view.presenter = presenter 

In addition, the author claims:

Since we do not want the View to know about the model, it is not right to represent the assembly when presenting the view controller (which is the view), so we need to do this somewhere else. For example, we can make the Router service for the entire application, which will be responsible for the assembly and the View-to-View.

My question is:

  • Where can I put the assembly code?
  • Where can I find another example of a router in an application ?
+5
source share
1 answer

So it's not just me who wondered;)

Let me share with you my other post about MVP in iOS:

Screencast by David Gadd - It's a bit long (1h 20min) and a bit old (December 2012), but certainly worth a look. You will see how MVP is implemented (in AppCode) for a very small application (along with a pretty good description of how to write unit tests). The router created by David is called ServiceLocator. Unfortunately, I could not find the code for downloading this screencast (but when viewing it you can create your own version of this application).

There may be other ways to create a router, but this screencast helped me figure this out a bit more. I am new to the MVP concept and I have not used it in a larger application (more than single-screen-let-s-see-how-it-is-done-app). It would be great to see how MVP was implemented in a real application ...

[EDIT]

I just realized that I did not answer your first questions.

According to the application in screencast, a router is a class with one class method:

 + (id)resolve:(PresenterTypeEnum)type; 

In implementing this method, you will find a simple switch. Based on the send type in the parameter method, it returns the correct instance of the master.

This method is called in viewDidLoad. When you have an instance of a facilitator, you just need to establish a representation of the facilitator using yourself.

I hope this explanation will be clear. In any case, I highly recommend watching screening, then it should be clean, like a crystal;)

+1
source

All Articles