I want to load an image from a custom cache (named "offline") for KFImage when using it in a SwiftUI view. I have tried various approaches, but I am still unable to apply the custom cache to KFImage. It works fine when setting images in UIKit.
Note: I have two caches
Default - General purpose. Memory and Disk expire after a couple of hours. Offline - for images that need to persist on disk forever or until internet access is regained an images are successfully uploaded to DB.
let url = URL(string: item.photoURL ?? "") ?? URL(string: "")!
let resource: ImageResource = ImageResource(downloadURL: url, cacheKey: item.photoURL)
KFImage(source: .network(resource))
.resizable()
.aspectRatio(contentMode: .fill)
.clipped()
.progressViewStyle(.linear)
.frame(width: size, height: size)
UIKit
capturedImageView.kf.setImage(with: imageURL, placeholder: nil, options: [
.scaleFactor(UIScreen.main.scale),
.transition(.fade(0.25)),
.targetCache(ImageCache(name: "offline")),
])
My work around: