Kingfisher Documentation

Protocol Image​Downloader​Delegate

public protocol ImageDownloaderDelegate: AnyObject  

Protocol of ImageDownloader. This protocol provides a set of methods which are related to image downloader working stages and rules.

%25 ImageDownloaderDelegate ImageDownloaderDelegate AnyObject AnyObject ImageDownloaderDelegate->AnyObject

Conforms To

AnyObject

Default Implementations

image​Downloader(_:​will​Download​Image​For​URL:​with:​)

public func imageDownloader(
        _ downloader: ImageDownloader,
        willDownloadImageForURL url: URL,
        with request: URLRequest?)  

image​Downloader(_:​did​Finish​Downloading​Image​For​URL:​with:​error:​)

public func imageDownloader(
        _ downloader: ImageDownloader,
        didFinishDownloadingImageForURL url: URL,
        with response: URLResponse?,
        error: Error?)  

image​Downloader(_:​did​Download:​for:​with:​)

public func imageDownloader(
        _ downloader: ImageDownloader,
        didDownload image: KFCrossPlatformImage,
        for url: URL,
        with response: URLResponse?)  

is​Valid​Status​Code(_:​for:​)

public func isValidStatusCode(_ code: Int, for downloader: ImageDownloader) -> Bool  

image​Downloader(_:​did​Download:​with:​)

public func imageDownloader(_ downloader: ImageDownloader, didDownload data: Data, with task: SessionDataTask) -> Data?  

image​Downloader(_:​did​Download:​for:​)

public func imageDownloader(_ downloader: ImageDownloader, didDownload data: Data, for url: URL) -> Data?  

Requirements

image​Downloader(_:​will​Download​Image​For​URL:​with:​)

func imageDownloader(_ downloader: ImageDownloader, willDownloadImageForURL url: URL, with request: URLRequest?) 

Called when the ImageDownloader object will start downloading an image from a specified URL.

Parameters

downloader Image​Downloader

The ImageDownloader object which is used for the downloading operation.

url URL

URL of the starting request.

request URLRequest?

The request object for the download process.

image​Downloader(_:​did​Finish​Downloading​Image​For​URL:​with:​error:​)

func imageDownloader(
        _ downloader: ImageDownloader,
        didFinishDownloadingImageForURL url: URL,
        with response: URLResponse?,
        error: Error?) 

Called when the ImageDownloader completes a downloading request with success or failure.

Parameters

downloader Image​Downloader

The ImageDownloader object which is used for the downloading operation.

url URL

URL of the original request URL.

response URLResponse?

The response object of the downloading process.

error Error?

The error in case of failure.

image​Downloader(_:​did​Download:​with:​)

func imageDownloader(_ downloader: ImageDownloader, didDownload data: Data, with dataTask: SessionDataTask) -> Data? 

Called when the ImageDownloader object successfully downloaded image data from specified URL. This is your last chance to verify or modify the downloaded data before Kingfisher tries to perform addition processing on the image data.

If this method is implemented, imageDownloader(_:didDownload:for:) will not be called anymore.

Parameters

downloader Image​Downloader

The ImageDownloader object which is used for the downloading operation.

data Data

The original downloaded data.

data​Task Session​Data​Task

The data task contains request and response information of the download.

image​Downloader(_:​did​Download:​for:​)

func imageDownloader(_ downloader: ImageDownloader, didDownload data: Data, for url: URL) -> Data? 

Called when the ImageDownloader object successfully downloaded image data from specified URL. This is your last chance to verify or modify the downloaded data before Kingfisher tries to perform addition processing on the image data.

Parameters

downloader Image​Downloader

The ImageDownloader object which is used for the downloading operation.

data Data

The original downloaded data.

url URL

The URL of the original request URL.

Returns

The data from which Kingfisher should use to create an image. You need to provide valid data which content is one of the supported image file format. Kingfisher will perform process on this data and try to convert it to an image object.

image​Downloader(_:​did​Download:​for:​with:​)

func imageDownloader(
        _ downloader: ImageDownloader,
        didDownload image: KFCrossPlatformImage,
        for url: URL,
        with response: URLResponse?) 

Called when the ImageDownloader object successfully downloads and processes an image from specified URL.

Parameters

downloader Image​Downloader

The ImageDownloader object which is used for the downloading operation.

image KFCross​Platform​Image

The downloaded and processed image.

url URL

URL of the original request URL.

response URLResponse?

The original response object of the downloading process.

is​Valid​Status​Code(_:​for:​)

func isValidStatusCode(_ code: Int, for downloader: ImageDownloader) -> Bool

Checks if a received HTTP status code is valid or not. By default, a status code in range 200..<400 is considered as valid. If an invalid code is received, the downloader will raise an KingfisherError with ResponseErrorReason.invalidHTTPStatusCode as its reason.

Parameters

code Int

The received HTTP status code.

downloader Image​Downloader

The ImageDownloader object asks for validate status code.

Returns

Returns a value to indicate whether this HTTP status code is valid or not.