Comments (1)
I've ended up doing something like this
import Kingfisher
import UIKit
struct NSDataAssetImageDataProvider: Kingfisher.ImageDataProvider {
let cacheKey: String
let dataAsset: NSDataAsset
init?(name: String, bundle: Bundle = .main) {
guard let dataAsset = NSDataAsset(name: name, bundle: bundle) else { return nil }
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)]
)
from kingfisher.
Related Issues (20)
- AVIF Support
- Support App Privacy Manifest HOT 1
- Extract data from processor .data and pass to .image HOT 2
- Kingfisher Support Base64 ? HOT 1
- [FR] Lottie动图支持
- AnimatedImageView 图片方向错误与heic格式文件卡顿
- Using LocalFileImageDataProvider not working after a while HOT 2
- Deprecation of the `UIGraphicsBeginImageContextWithOptions` in Xcode15 HOT 2
- support visionOS via CocoaPods HOT 2
- App crashed for GIF images
- 清除图片的缓存 HOT 3
- Resizing an UIImageView via UIViewPropertyAnimator makes loaded image disappear and placeholder appear HOT 3
- `defaultOptions` only invokes _last_ `requestModifier` in chain HOT 2
- How to refresh cache same url while in use props: .resizing() and downsampling() on SwiftUI HOT 2
- 部分jpg图片链接无法显示的问题,kf.setImage(with: URL(string: url), placeholder: placeholder) HOT 5
- ImageProgressive.swift:121 Crash HOT 2
- Diskstorage.swift:224 (fileManager.fileExists(atPath: filePath) 文件IO耗时导致卡顿 HOT 2
- Memory Leak HOT 3
- Privacy Report HOT 4
- 约定的图片地址实际资源为视频时,在列表中加载这种资源,内存激增导致 App 闪退。 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kingfisher.