I am using king fisher library but my problem is that I can't use this for images that stored in the asset- all of the kingfisher methods need url, so how can I use this for assets?
Asked
Active
Viewed 4,398 times
1
-
5Kingfisher library is used to download image from web and store it in cache. It reduces the network usage and allows the app to reuse when it is needed to load same image multiple times. There is no need to use suck libraries for asset images. – RajeshKumar R Jan 09 '19 at 09:13
-
1KingFisher is a library used to manage downloading and caching *remote* images. it is not designed for local images and not needed. just use UIImage(named: "whatever") for assets – Scriptable Jan 09 '19 at 09:13
-
I know how to use local files but I wanted to use king fisher filters for that images so I can't use king fisher for assets right? – Saeed Rahmatolahi Jan 09 '19 at 09:56
-
1I assume you could point to an image using local URL, but since assets are stored specifically, I don't think you'll be able to do that - check this https://stackoverflow.com/questions/21769092/can-i-get-a-nsurl-from-an-xcassets-bundle – Milan Nosáľ Jan 09 '19 at 10:21
-
What "filters" are you looking for exactly? – Larme Jan 09 '19 at 11:52
-
I want to dark my Image look like when you put a view infront of the photo and make that black and change the alpha or opacity of that to 0.5 – Saeed Rahmatolahi Jan 10 '19 at 04:52
1 Answers
8
Those who are saying in the comments that we don't need to load local Image from Assets through kingfisher for them, there is a scenario, for example when we are loading images in UITableView and under if condition we load image from remote URL and in else condition, we load from local assets. In that scenario, if we directly assign an image with UIImage(...)
method, TableView images will start behaving abnormally. So we need to inform to Kingfisher that we have directly changed the image and don't update it when it's loaded from the remote URL.
For this kind of scenario, you can use the following code
import Kingfisher
//////// In your cellForRowAt method
if (loadThroughRemoteURL) {
cell.imageView.kf.setImage(with: URL(string: "YOUR_REMOTE_IMAGE_URL"))
}
else { // loading through local assets
let resource: Resource? = nil
cell.imageView.kf.setImage(with: resource) // inform kingfisher that you are assigning this image by your own
cell.imageView.image = UIImage(named: "your_image_in_assets")
}

Asad Ali Choudhry
- 4,985
- 4
- 31
- 36
-
Another reason to use Kingfisher would be if you want to load a WebP image from Assets. A feature that Xcode doesn't natively support. – Ezequiel Adrian Aug 12 '23 at 17:36