1

I do have few questions. What the best way to use interactor:

Let's say in interactor I save some data, but I want to check this data and show next alert:

self.presenter?.showAlert(with: "All fields are required for adding exercise.".localized)

First question is this violation of Viper? And do I need to check data in presenter before passing it to interceptor?

Another question: Do I need to use function showAlertFillIssue instead of passing text?

Even let's say I will pass it from presenter in case of violation of interactor.

Andreas ZUERCHER
  • 862
  • 1
  • 7
  • 20
Matrosov Oleksandr
  • 25,505
  • 44
  • 151
  • 277

2 Answers2

1

As described in https://TheSwiftDev.com/the-ultimate-viper-architecture-tutorial,

  • the interactor zone is solely for the acquisition of entities from sensors, database, or network protocols or for the emission of entities to database or network protocols.
  • Conversely, the presenter zone is for all the enforcement of business rules/logic. There are occasionally shades of grey (as mentioned below) but the general rule is that the detection of not all fields being filled out properly would be in presenter divorced from database concepts and divorced from UI concepts.
  • The showAlert would be best thought of as something entirely in the view zone, because, depending on the OS, it might be an alert on 1 OS but some nonalert UI construct on another OS. It is best to think of VIPER as: what would this action look like on all the other OSes (than iOS), such as at least MacOS but also Android & UWP (or other UI infrastructure quarantined in view zone, such as Qt). It would be best to reword showAlert as emitError or balkBack more generically without referring to what the actual UI construct is on this OS. Likewise, the showAlertFillIssue and any other specific UI action is best quarantined entirely within view zone away from presenter (business rules) and from interactor (entity acquisition & storage).
Andreas ZUERCHER
  • 862
  • 1
  • 7
  • 20
0

Hi with Viper Architechture, The interractor contains the business logic. So when validating your data. You may call a method from your presenter to display an error message. You can define an enum to handle errors and passe it to the showAlert methods.

self.presenter?.showAlert(with: FormError.AllFieldRequired)
Gsabatie
  • 64
  • 3
  • 1
    No, the interactor zone is for all of the ways of data acquisition from databases or sensors or network. Presenter zone is for the business logic. (Yes, there are the rules for how to operate the database, how to interact with the sensor, and the network protocol, but these are infrastructural rules, not business rules of the app's app-domain.) – Andreas ZUERCHER Apr 07 '21 at 18:44
  • 1
    yea I agree with @AndreasZUERCHER that only one layer in VIPER should controls this behaviour. Which is presenter. We simple get some data from services and return it back to presenter which decides what to do whether validate this data or do other actions. – Matrosov Oleksandr Apr 07 '21 at 21:09