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.

  • Represents a shared manager used across Kingfisher. Use this instance for getting or storing images with Kingfisher.

    Declaration

    Swift

    public static let shared: KingfisherManager
  • The ImageCache used by this manager. It is ImageCache.default by default. If a cache is specified in KingfisherManager.defaultOptions, the value in defaultOptions will be used instead.

    Declaration

    Swift

    public var cache: ImageCache
  • The ImageDownloader used by this manager. It is ImageDownloader.default by default. If a downloader is specified in KingfisherManager.defaultOptions, the value in defaultOptions will be used instead.

    Declaration

    Swift

    public var downloader: ImageDownloader
  • Default options used by the manager. This option will be used in Kingfisher manager related methods, as well as all view extension methods. You can also passing other options for each image task by sending an options parameter to Kingfisher’s APIs. The per image options will overwrite the default ones, if the option exists in both.

    Declaration

    Swift

    public var defaultOptions: KingfisherOptionsInfo
  • Creates an image setting manager with specified downloader and cache.

    Declaration

    Swift

    public init(downloader: ImageDownloader, cache: ImageCache)

    Parameters

    downloader

    The image downloader used to download images.

    cache

    The image cache which stores memory and disk 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,
        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.

    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,
        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.

    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.

  • 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.