ImageDownloaderDelegate

public protocol ImageDownloaderDelegate: class

Protocol of ImageDownloader.

  • Called when the ImageDownloader object successfully downloaded an image from specified URL.

    Default Implementation

    Declaration

    Swift

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

    Parameters

    downloader

    The ImageDownloader object finishes the downloading.

    image

    Downloaded image.

    url

    URL of the original request URL.

    response

    The response object of the downloading process.

  • Called when the ImageDownloader object starts to download an image from specified URL.

    Default Implementation

    Declaration

    Swift

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

    Parameters

    downloader

    The ImageDownloader object starts the downloading.

    url

    URL of the original request.

    response

    The request object of the downloading process.

  • isValidStatusCode(_:for:) Default implementation

    Check if a received HTTP status code is valid or not. By default, a status code between 200 to 400 (excluded) is considered as valid. If an invalid code is received, the downloader will raise an .invalidStatusCode error. It has a userInfo which includes this statusCode and localizedString error message.

    Note

    If the default 200 to 400 valid code does not suit your need, you can implement this method to change that behavior.

    Default Implementation

    Declaration

    Swift

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

    Parameters

    code

    The received HTTP status code.

    downloader

    The ImageDownloader object asking for validate status code.

    Return Value

    Whether this HTTP status code is valid or not.

  • imageDownloader(_:didDownload:for:) Default implementation

    Called when the ImageDownloader object successfully downloaded image data from specified URL.

    Note

    This callback can be used to preprocess raw image data before creation of UIImage instance (i.e. decrypting or verification).

    Default Implementation

    Declaration

    Swift

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

    Parameters

    downloader

    The ImageDownloader object finishes data downloading.

    data

    Downloaded data.

    url

    URL of the original request URL.

    Return Value

    The data from which Kingfisher should use to create an image.