I have the following MVVM architecture. It is not something special, just for better understanding.
What is the main question is:
How do I need to bind UIButton action to make some reaction in UIViewController.
I try to do it the following way:
1) First of all, I add the property as a closure for ViewModel:
var cellButtonActionCallback: (() -> Void)?
2) I add the same property for CellViewModel:
var buttonCallback: (() -> Void)?
3) When I setup CellViewModel do:
cellViewModel.buttonCallback = cellButtonActionCallback
4) And finally add target for UIButton, and selector buttonAction
calls buttonCallback as well:
button.bind { cellViewModel.buttonAction() }
Looks like closure which I define on UITableViewController goes through all viewModels which is not a good idea in my way.
Actually, this approach works fine, but I don't like it.
What is the best way to make the same thing?