Article From:https://www.cnblogs.com/Blueleaf-tech/p/9811759.html

VIP(ViewController-Interactor-Presenter)Framework:

  This structure is suitable for scenarios: version iteration is frequent, function is complex, developers are not fixed, and it is difficult to test and maintain. In test maintenance, the error code can be located more quickly for the error part. For those who take over the project halfway, the composition of this module can be better understood.

Clean Swift(https://clean-swift.com/clean-swift-ios-architecture/):

  XcodeThe VIP development template of Scene provides the templates of ViewController, Interactor, Presenter, Worker, Router and Model, in which Scene can create a complete VIP structure.

 

ViewController

Responsible for presentation of views

It acts asPresenterOfoutput,fromPresenterAcquiredViewModelTo assign data to views,ViewControllerIt does not process data in any way, but only fromViewModelGet in,ViewModelIt shows whatever data it gives.
At the same time, it also acts as aInteractorOfinput,When the user interacts with the interface, it takes this event and the parameters needed to handle it as oneRequestprovide forInteractor,Give WayInteractorTo handle this interactive event.

Interactor

Handling events that occur when users interact with the interface

It acts asViewControllerOfoutput,WhenViewControllerInteractive events are triggered with the user.InteractorWill come fromViewControllerProvidedRequestIn fact, it is a manager of event processing. There are many workers working for it, such as the workers who request the negative network, the workers who query the database. These workers are the real handlers.The basic unit of the document (more detailed pictures will be introduced later).
At the same time, it also acts as aPresenterOfinput,When the worker gets the data, the result is encapsulated into oneResponseIt is then provided toPresenterTo deal with.

Presenter

Data processing into the content of the view to be displayed

It acts asInteractorOfoutput,takeInteractorProvidedResponseProcessing, sometimes we just need toResponseSome of the data, or some sort of data processing, are done here, and the data is encapsulated after processing.ViewModel
At the same time, it also acts as aViewControllerOfinput,byViewControllerThe view is presented with the necessary and processed data.

Worker

The above is introduced.InteractorAs mentioned, they are in theInteractorThe basic unit in which events are really handled, eachWorkerThey have a single responsibility. For tasks requiring network requests, invoke those responsible for network requestsWorker,If you need to update or retrieve the database, you can call the one responsible for the database processing.Worker,We can define many different types of events by event type.WorkerWorkerAfter processing, the processing is called back toInteractor

Models

When inViewControllerWhen interacting with users, fromViewControllerreachInteractorUntil thenPresentrtFinally backViewControllerThere will be a series ofRequestResponseandViewModel。For each particular event, there is a specificRequestResponseandViewModel,So inModelsIn Swift, we will use Swift’s unique namespace to define a namespace for each event, which containsRequestResponseandViewModelThese threeModel

  • Request:Some parameters needed for network requests or database queries.
  • Response:Some data returned by network requests or database queries.
  • ViewModel:Processing Response into data that the view needs to display.

Router

Routers, as the name implies, are used for page hopping. stayRouterInside, we need to pass it according to the situation.segueJump, or passStoryboardorXIBTo create, or directly through code creation, and initialize the new controller assignment, and finally jump. For the initialization assignment of the new controller, we passRouterInsideDataStoreAttributes are acquired, and as suchRouterOfDataStoreNamelyInteractor,Because page Jump also belongs to user interaction, it is a jump event. Before jumping, it needs to be handled before jumping, after processing.RouterIn fromInteractorGet data to initialize the controller.

 

 

Refer to Link:

  VIPIntroduction: https://www.jianshu.com/p/956c34d5f7c8

 

Leave a Reply

Your email address will not be published. Required fields are marked *