vendredi 21 juillet 2017

iOS: Use UIImage in ViewModel(from MVVM) and in Presenter(from MVP)

I'm trying to figure out in MVVM and MVP architecture designs. I've decided to write simple one screen application with different design approaches.

Few words about sample application:

  • It's a simple image loader
  • Flow: Loads JSON with pictures from 500px -> Shows cells in UICollectionView depends on count pictures in returned JSON -> Gradually downloads pictures and displays it in cells
  • The same applications I'm implementing under 3 architecture designs MVVM, MVC and MVP

Everything was going smoothly until I've needed to download images and display them 😅 .

Initially I've though that the best place for handling this logic and caching pictures is ViewModel(from MVVM) and in Presenter(from MVP) but AFAIK these two entities should be independent from UI layer, but if we want to use UIImage there it means that we should import UIKit in ViewModel/Presenter đŸ€”

So, questions

  1. Can I use import UIKit in ViewModel/Presenter?
  2. What is the best place for Load&Store UIImage in this UIViewController, ViewModel/Presenter or something else?

GitHub link on sample application

MVVM Diagram MVP Diagram

Aucun commentaire:

Enregistrer un commentaire