Nuke Documentation

Class Image​Pipeline

public final class ImagePipeline  

ImagePipeline is the primary way to load images directly (without a UI).

The pipeline is fully customizable. You can change its configuration using ImagePipeline.Configuration type: set custom data loader and cache, configure image encoders and decoders, etc. You can also set an ImagePipelineDelegate to get even more granular control on a per-request basis.

See "Image Pipeline" to learn more about how to use the pipeline. You can also learn about they way it works internally in a dedicated guide.

ImagePipeline also suppors Combine. You can learn more in a dedicated guide with some common use-cases.

ImagePipeline is fully thread-safe.

Nested Types

ImagePipeline.Cache

Provides a set of convenience APIs for managing the pipeline cache layers, including ImageCaching (memory cache) and DataCaching (disk cache).

ImagePipeline.Error

Represents all possible image pipeline errors.

ImagePipeline.Configuration

The pipeline configuration.

Initializers

init(configuration:​delegate:​)

public init(configuration: Configuration = Configuration(), delegate: ImagePipelineDelegate? = nil)  

Initializes ImagePipeline instance with the given configuration.

Parameters

configuration Configuration

Configuration() by default.

delegate Image​Pipeline​Delegate?

nil by default.

init(delegate:​_:​)

public convenience init(delegate: ImagePipelineDelegate? = nil, _ configure: (inout ImagePipeline.Configuration) -> Void)  

Properties

shared

public static var shared  

Shared image pipeline.

configuration

public let configuration: Configuration

The pipeline configuration.

cache

public var cache: ImagePipeline.Cache  

Provides access to the underlying caching subsystems.

Methods

image​Publisher(with:​)

func imagePublisher(with request: ImageRequestConvertible) -> ImagePublisher  

Returns a publisher which starts a new ImageTask when a subscriber is added.

invalidate()

public func invalidate()  

Invalidates the pipeline and cancels all outstanding tasks. No new requests can be started.

load​Image(with:​completion:​)

@discardableResult public func loadImage(
        with request: ImageRequestConvertible,
        completion: @escaping (_ result: Result<ImageResponse, Error>) -> Void
    ) -> ImageTask  

Loads an image for the given request.

load​Image(with:​queue:​progress:​completion:​)

@discardableResult public func loadImage(
        with request: ImageRequestConvertible,
        queue: DispatchQueue? = nil,
        progress: ((_ response: ImageResponse?, _ completed: Int64, _ total: Int64) -> Void)?,
        completion: @escaping ((_ result: Result<ImageResponse, Error>) -> Void)
    ) -> ImageTask  

Loads an image for the given request.

See Nuke Docs to learn more.

Parameters

request Image​Request​Convertible

An image request.

queue Dispatch​Queue?

A queue on which to execute progress and completion callbacks. By default, the pipeline uses .main queue.

progress ((_ response:​ Image​Response?, _ completed:​ Int64, _ total:​ Int64) -> Void)?

A closure to be called periodically on the main thread when the progress is updated. nil by default.

completion @escaping ((_ result:​ Result<Image​Response, Error>) -> Void)

A closure to be called on the main thread when the request is finished. nil by default.

image(for:​)

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.0, *)
    public func image(for request: ImageRequestConvertible) async throws -> ImageResponse  

Loads an image for the given request.

See Nuke Docs to learn more.

Parameters

request Image​Request​Convertible

An image request.

load​Data(with:​completion:​)

@discardableResult public func loadData(
        with request: ImageRequestConvertible,
        completion: @escaping (Result<(data: Data, response: URLResponse?), Error>) -> Void
    ) -> ImageTask  

Loads the image data for the given request. The data doesn't get decoded or processed in any other way.

load​Data(with:​queue:​progress:​completion:​)

@discardableResult public func loadData(
        with request: ImageRequestConvertible,
        queue: DispatchQueue? = nil,
        progress: ((_ completed: Int64, _ total: Int64) -> Void)?,
        completion: @escaping (Result<(data: Data, response: URLResponse?), Error>) -> Void
    ) -> ImageTask  

Loads the image data for the given request. The data doesn't get decoded or processed in any other way.

You can call loadImage(:) for the request at any point after calling loadData(:), the pipeline will use the same operation to load the data, no duplicated work will be performed.

Parameters

request Image​Request​Convertible

An image request.

queue Dispatch​Queue?

A queue on which to execute progress and completion callbacks. By default, the pipeline uses .main queue.

progress ((_ completed:​ Int64, _ total:​ Int64) -> Void)?

A closure to be called periodically on the main thread when the progress is updated. nil by default.

completion @escaping (Result<(data:​ Data, response:​ URLResponse?), Error>) -> Void

A closure to be called on the main thread when the request is finished.

data(for:​)

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.0, *)
    public func data(for request: ImageRequestConvertible) async throws -> (Data, URLResponse?)  

Loads an image for the given request.

See Nuke Docs to learn more.

Parameters

request Image​Request​Convertible

An image request.