I am working on a small SwiftUI project as I believe this is the best way of learning anything. Coming from the background of UIKit sometime I do get confused with how to do this in SwiftUI.

What I want to achieve and why?

I want to render a list of lazy loading cells containing images and Cache them. Now SwiftUI provides a very clean way to do this i.e.., via AsyncImage. AsyncImage in my opinion is good for lazy loading images but it doesn't have any functionality to cache any thing.

So I have two choices either to write my own implementation of caching mechanism or use anything reliable from community and we do have SdWebImageSwiftUI and Kingfisher which will do most of the heavy lifting and are reliable enough for the result I want to achieve so I am good with any of the two libraries.

Now what I actually want to achieve? I just want to encapsulate the usage of any of these libraries so that in future if I want to replace them with something else then I don't have to make changes everywhere in the application. While doing so I do want to keep the functionality to add view modifiers to the view which we would be using.

Eg.

CachedImage(url: url_for_image)
.resizable()
.frame(width: x, height: y)
.scaleAspectFit()
.
.
.

The implementation which I am proposing might not be the best and I am very open to listen to the community for what can be the better way of doing this.

Please do correct me if I am wrong somewhere.

0

There are 0 best solutions below