Kingfisher Documentation

Class Image​Downloader

open class ImageDownloader  

Represents a downloading manager for requesting the image with a URL from server.

Initializers

init(name:​)

public init(name: String)  

Creates a downloader with name.

Parameters

name String

The name for the downloader. It should not be empty.

Properties

`default`

public static let `default`  

The default downloader.

download​Timeout

open var downloadTimeout: TimeInterval = 15.0

The duration before the downloading is timeout. Default is 15 seconds.

trusted​Hosts

open var trustedHosts: Set<String>? 

A set of trusted hosts when receiving server trust challenges. A challenge with host name contained in this set will be ignored. You can use this set to specify the self-signed site. It only will be used if you don't specify the authenticationChallengeResponder.

If authenticationChallengeResponder is set, this property will be ignored and the implementation of authenticationChallengeResponder will be used instead.

session​Configuration

open var sessionConfiguration = URLSessionConfiguration.ephemeral  

Use this to set supply a configuration for the downloader. By default, NSURLSessionConfiguration.ephemeralSessionConfiguration() will be used.

You could change the configuration before a downloading task starts. A configuration without persistent storage for caches is requested for downloader working correctly.

session​Delegate

open var sessionDelegate: SessionDelegate  

requests​Use​Pipelining

open var requestsUsePipelining = false

Whether the download requests should use pipeline or not. Default is false.

delegate

open weak var delegate: ImageDownloaderDelegate? 

Delegate of this ImageDownloader object. See ImageDownloaderDelegate protocol for more.

authentication​Challenge​Responder

open weak var authenticationChallengeResponder: AuthenticationChallengeResponsable? 

A responder for authentication challenge. Downloader will forward the received authentication challenge for the downloading session to this responder.

Methods

download​Image(with:​options:​completion​Handler:​)

@discardableResult
    open func downloadImage(
        with url: URL,
        options: KingfisherParsedOptionsInfo,
        completionHandler: ((Result<ImageLoadingResult, KingfisherError>) -> Void)? = nil) -> DownloadTask? 

Downloads an image with a URL and option. Invoked internally by Kingfisher. Subclasses must invoke super.

Parameters

url URL

Target URL.

options Kingfisher​Parsed​Options​Info

The options could control download behavior. See KingfisherOptionsInfo.

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

Called when the download progress finishes. This block will be called in the queue defined in .callbackQueue in options parameter.

Returns

A downloading task. You could call cancel on it to stop the download task.

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

@discardableResult
    open func downloadImage(
        with url: URL,
        options: KingfisherOptionsInfo? = nil,
        progressBlock: DownloadProgressBlock? = nil,
        completionHandler: ((Result<ImageLoadingResult, KingfisherError>) -> Void)? = nil) -> DownloadTask? 

Downloads an image with a URL and option.

Parameters

url URL

Target URL.

options Kingfisher​Options​Info?

The options could control download behavior. See KingfisherOptionsInfo.

progress​Block Download​Progress​Block?

Called when the download progress updated. This block will be always be called in main queue.

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

Called when the download progress finishes. This block will be called in the queue defined in .callbackQueue in options parameter.

Returns

A downloading task. You could call cancel on it to stop the download task.

download​Image(with:​options:​completion​Handler:​)

@discardableResult
    open func downloadImage(
        with url: URL,
        options: KingfisherOptionsInfo? = nil,
        completionHandler: ((Result<ImageLoadingResult, KingfisherError>) -> Void)? = nil) -> DownloadTask? 

Downloads an image with a URL and option.

Parameters

url URL

Target URL.

options Kingfisher​Options​Info?

The options could control download behavior. See KingfisherOptionsInfo.

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

Called when the download progress finishes. This block will be called in the queue defined in .callbackQueue in options parameter.

Returns

A downloading task. You could call cancel on it to stop the download task.

cancel​All()

public func cancelAll()  

Cancel all downloading tasks for this ImageDownloader. It will trigger the completion handlers for all not-yet-finished downloading tasks.

If you need to only cancel a certain task, call cancel() on the DownloadTask returned by the downloading methods. If you need to cancel all DownloadTasks of a certain url, use ImageDownloader.cancel(url:).

cancel(url:​)

public func cancel(url: URL)  

Cancel all downloading tasks for a given URL. It will trigger the completion handlers for all not-yet-finished downloading tasks for the URL.

Parameters

url URL

The URL which you want to cancel downloading.