KingfisherManager

public class KingfisherManager

Main manager class of Kingfisher. It connects Kingfisher downloader and cache, to provide a set of convenience methods to use Kingfisher for tasks. You can use this class to retrieve an image via a specified URL from web or cache.

Getting Images

  • Gets an image from a given resource.

    Note

    This method will first check whether the requested resource is already in cache or not. If cached, it returns nil and invoke the completionHandler after the cached image retrieved. Otherwise, it will download the resource, store it in cache, then call completionHandler.

    Declaration

    Swift

    @discardableResult
    public func retrieveImage(
        with resource: Resource,
        options: KingfisherOptionsInfo? = nil,
        progressBlock: DownloadProgressBlock? = nil,
        downloadTaskUpdated: DownloadTaskUpdatedBlock? = nil,
        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)?) -> DownloadTask?

    Parameters

    resource

    The Resource object defines data information like key or URL.

    options

    Options to use when creating the animated image.

    progressBlock

    Called when the image downloading progress gets updated. If the response does not contain an expectedContentLength, this block will not be called. progressBlock is always called in main queue.

    downloadTaskUpdated

    Called when a new image downloading task is created for current image retrieving. This usually happens when an alternative source is used to replace the original (failed) task. You can update your reference of DownloadTask if you want to manually cancel the new task.

    completionHandler

    Called when the image retrieved and set finished. This completion handler will be invoked from the options.callbackQueue. If not specified, the main queue will be used.

    Return Value

    A task represents the image downloading. If there is a download task starts for .network resource, the started DownloadTask is returned. Otherwise, nil is returned.

  • Gets an image from a given resource.

    Note

    This method will first check whether the requested source is already in cache or not. If cached, it returns nil and invoke the completionHandler after the cached image retrieved. Otherwise, it will try to load the source, store it in cache, then call completionHandler.

    Declaration

    Swift

    public func retrieveImage(
        with source: Source,
        options: KingfisherOptionsInfo? = nil,
        progressBlock: DownloadProgressBlock? = nil,
        downloadTaskUpdated: DownloadTaskUpdatedBlock? = nil,
        completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)?) -> DownloadTask?

    Parameters

    source

    The Source object defines data information from network or a data provider.

    options

    Options to use when creating the animated image.

    progressBlock

    Called when the image downloading progress gets updated. If the response does not contain an expectedContentLength, this block will not be called. progressBlock is always called in main queue.

    downloadTaskUpdated

    Called when a new image downloading task is created for current image retrieving. This usually happens when an alternative source is used to replace the original (failed) task. You can update your reference of DownloadTask if you want to manually cancel the new task.

    completionHandler

    Called when the image retrieved and set finished. This completion handler will be invoked from the options.callbackQueue. If not specified, the main queue will be used.

    Return Value

    A task represents the image downloading. If there is a download task starts for .network resource, the started DownloadTask is returned. Otherwise, nil is returned.

Deprecated

  • Get an image with resource. If .empty is used as options, Kingfisher will seek the image in memory and disk first. If not found, it will download the image at resource.downloadURL and cache it with resource.cacheKey. These default behaviors could be adjusted by passing different options. See KingfisherOptions for more.

    Declaration

    Swift

    @available(*, deprecated, message: "Use `Result` based callback instead.")
    @discardableResult
    public func retrieveImage(with resource: Resource,
                              options: KingfisherOptionsInfo?,
                              progressBlock: DownloadProgressBlock?,
                              completionHandler: CompletionHandler?) -> DownloadTask?

    Parameters

    resource

    Resource object contains information such as cacheKey and downloadURL.

    options

    A dictionary could control some behaviors. See KingfisherOptionsInfo for more.

    progressBlock

    Called every time downloaded data changed. This could be used as a progress UI.

    completionHandler

    Called when the whole retrieving process finished.

    Return Value

    A RetrieveImageTask task object. You can use this object to cancel the task.