Kingfisher Documentation

Class Kingfisher​Manager

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.

Initializers

init(downloader:​cache:​)

public init(downloader: ImageDownloader, cache: ImageCache)  

Creates an image setting manager with specified downloader and cache.

Parameters

downloader Image​Downloader

The image downloader used to download images.

cache Image​Cache

The image cache which stores memory and disk images.

Properties

shared

public static let shared  

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

cache

public var cache: ImageCache

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.

downloader

public var downloader: ImageDownloader

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.

default​Options

public var defaultOptions = KingfisherOptionsInfo.empty

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.

Methods

retrieve​Image(with:​options:​progress​Block:​download​Task​Updated:​completion​Handler:​)

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

Gets an image from a given resource.

Parameters

resource Resource

The Resource object defines data information like key or URL.

options Kingfisher​Options​Info?

Options to use when creating the image.

progress​Block Download​Progress​Block?

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.

download​Task​Updated Download​Task​Updated​Block?

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.

completion​Handler ((Result<Retrieve​Image​Result, Kingfisher​Error>) -> Void)?

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.

Returns

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.

retrieve​Image(with:​options:​progress​Block:​download​Task​Updated:​completion​Handler:​)

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

Gets an image from a given resource.

Parameters

source Source

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

options Kingfisher​Options​Info?

Options to use when creating the image.

progress​Block Download​Progress​Block?

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.

download​Task​Updated Download​Task​Updated​Block?

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.

completion​Handler ((Result<Retrieve​Image​Result, Kingfisher​Error>) -> Void)?

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.

Returns

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.