Open mathewaj opened 9 years ago
Honestly, I'd simple use the UIImageView
category from https://github.com/AFNetworking/AFNetworking. This is clearly a violation of layer boundaries but it is nicely abstracted and if you really don't need any custom logic in between view and image endpoint, I'd say this one-liner is an efficient and appropriate solution.
Plus, it will only trigger when the image view is actually displayed which may not be the case for every image view in a 100 row table view. Why load all 100 images when some of them might not even be visible?
But to do it manually I'd suggest the following:
Nothing official, just my 2 cents.
P.S. You don't get around to keeping a reference to the data model within the view model if you want to edit or reuse it (e.g. in a master-detail view). Lots of information is getting lost from the database to the view, so you have to know where the data comes from. Either you have a view model for more than one screen as a compromise (which sucks IMHO) or you keep an ID reference which is a slight layer violation but still quite elegant.
I'd be interested to hear how lazy loading images in a tableview would be approached in this architecture? I noticed cellForRowAtIndexPath is placed in the view class, does this mean one should:
Would be great to hear any thoughts.