ViewModel and UIKit
IvanKalaica opened this issue · comments
Should viewModel import framework that exposes UIKit like RxCocoa? Maybe it's better to expose input/output as Observable's and convert them to Driver in viewController implementation where it's legit to import RxCocoa?
Hi, @IvanKalaica! Yeah, I've heard quite a lot people saying that ViewModel
should be platform agnostic e.g in case you would want to make a MacOS app, but IMHO this is not possible ¯_(ツ)_/¯
And regarding Input/Output
approach, at the moment I'm not sure if it's visible solution in more complex examples. We recently started to use RxFeedback in our app and we are very happy =)
Yeah, I also use RxFeedback also in my projects inside ViewModel with input/output as Observables. Currently this doesn't make sense since RxFeedback imports RxCocoa. It would be good if I can import just a Observable RxFeedback. Then it's possible to have platform agnostic ViewModel.
How do you work with UIImage
for example?
I would expose var imageData: Observable<Data?>
in ViewModel and convert it on async scheduler to format I need (UIImage) where I need it (cell or viewController).
IMHO it violates original design idea ¯_(ツ)_/¯
The view model then provides data from the model in a form that the view can easily use.
from here
Yeah, I know and I agree. :)
I think UIImage is only data type for which I had to make such transformation outside ViewModel.
IMHO it's small price to pay considering the benefits.
and UIFont, UIColor... I think the price raises as time passes. :)