user3745888
user3745888

Reputation: 6353

Where is the better place for a function used on a lot of controllers using VIPER?

I'm using VIPER pattern within my Swift app. I need a function that is executed in a lot of controllers to open a cardViewStyle. I don't know where is the better place to add this function...

Could be a useCase? An Interactor?, common... I haven't been able to visualize how VIPER and clean architecture would handle such a function.

For now the function is into view controller, into presenter and wireframe, because is called only one time.

The function would be like:

//Presenter
func showLikeCard(controller: UIViewController){ 
     wireframe.showLikeCard(controller: controller)
}

//Wireframe
func showLikeCard(controller: UIViewController){ 
     controller.present()
}

Thanks!

Upvotes: 3

Views: 125

Answers (1)

Andreas ZUERCHER
Andreas ZUERCHER

Reputation: 902

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

  • The view zone is for all things UI. Because your commonality factored out from multiple UIViewController view-controllers is UI related, it should be quarantined in the view zone. Despite your //Presenter comment, this appears to have nothing to do with enforcement of business rules over in VIPER's presenter zone. (If it does, then an inter-zone interface should be redesigned so that it refers to purely app-domain entities without referring to UI-centric constructs like UIViewController, because UIViewController itself has nothing related to business-rule enforcement.) This separation of concerns is how VIPER dismantles the entire Massive View Controller architecture's problem of excessive commingling due to insufficient quarantining and insufficient compartmentalization of concerns away from each other.
  • It would not be within interactor zone unless it was acquiring data from database, network, or sensor.

Upvotes: 0

Related Questions