FAQ - qingkong1998/qingkong GitHub Wiki

I cannot download an image.

Please check whether you are trying to access with an image resource with "http" scheme. If so, you need to switch to "https" or disable ATS in your Info.plist.

It seems that the memory usage increases unbounded

Kingfisher is using an aggressive cache policy by default. It will put all loaded image into NSCache and will not purge it unless a memory warning is received. In general, it is fine and we could take use all available resources to enhance user experience. There should be nothing to worry about.

However, if you need to keep a small memory footprint, you could limit the memory cache used by setting the maxMemoryCost of ImageCache.default to a small value. For example, this will "disable" the memory cache:

ImageCache.default.maxMemoryCost = 1

Or you could call ImageCache.default.clearMemoryCache() when necessary (before you need to do some memory consuming operation). This will free the memory cache, so you could avoid a memory using peak.

The image cannot be cached and every time I have to download it again.

Kingfisher is using a hashed the url absolute string for cache key by default. So if your url changes, even only the query part or timestamp, Kingfisher will think that it is a new image which is not cached yet.

Can I load some special image format like WebP?

Yes, but it is not built-in supported in Kingfisher. You may need to implement your own ImageProcessor and CacheSerializer. It is also already done by some other libraries, for example, KingfisherWebP. For more discussion on this topic, search for "webp" in the issues.

Does Kingfisher supports authentication with server?

Yes. You could setup an ImageDownloadRequestModifier and pass it in option to modify the request header. It is useful when you are doing a basic HTTP authentication or any token based authentication. If you are using some certification, please set authenticationChallengeResponder of ImageDownloader and implement your auth logic in the delegate method.

Can I just download or get the image without setting to the image view?

Sometimes you are not doing UI things and just want the image. You could use KingfisherManager for it:

KingfisherManager.shared.retrieveImage(with: url) { 
    (image, error, cacheType, url) in
    if let image = image {
        // Use image
    }
}

This will check the cache first, if the image is not cached yet, it will download it from given url. If you need more control of it, use ImageDownloader and ImageCache instead.