You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import Kingfisher
import UIKit
structNSDataAssetImageDataProvider:Kingfisher.ImageDataProvider{letcacheKey:StringletdataAsset:NSDataAssetinit?(name:String, bundle:Bundle=.main){
guard let dataAsset =NSDataAsset(name: name, bundle: bundle)else{returnnil}self.dataAsset = dataAsset
self.cacheKey ="\(bundle.bundlePath)/\(dataAsset.name).\(dataAsset.typeIdentifier)"}func data(handler:@escaping(Result<Data,Error>)->Void){handler(.success(dataAsset.data))}}// somewhere where you want to use it
guard let gifResource =NSDataAssetImageDataProvider(name:"yourDataSetName")else{return}// I do not cache on disk because reading from assets is faster than reading from disk. Caching to disk will also prevent easy updates of resources because they are cached by path, and there's no way as fas as I know to know if an asset has changed without explicitly changing it's name.
imageView.kf.setImage(
with: gifResource,
options:[.diskCacheExpiration(.expired)])
Check List
Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.
Issue Description
What
I want to use kingfisher load gif from assets, but I can not find any solutions.
[Tell us about the issue]
Reproduce
[The steps to reproduce this issue. What is the url you were trying to load, where did you put your code, etc.]
Other Comment
[Add anything else here]
The text was updated successfully, but these errors were encountered: