Class
ImagePipeline
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.
Relationships
Nested Types
ImagePipeline.Cache
Provides a set of convenience APIs for managing the pipeline cache layers, including
ImageCaching
(memory cache) andDataCaching
(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
Name | Type | Description |
---|---|---|
configuration | Configuration |
|
delegate | ImagePipelineDelegate? |
|
init(delegate:_:)
public convenience init(delegate: ImagePipelineDelegate? = nil, _ configure: (inout ImagePipeline.Configuration) -> Void)
Properties
Methods
imagePublisher(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.
loadImage(with:completion:)
@discardableResult public func loadImage(
with request: ImageRequestConvertible,
completion: @escaping (_ result: Result<ImageResponse, Error>) -> Void
) -> ImageTask
Loads an image for the given request.
loadImage(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
Name | Type | Description |
---|---|---|
request | ImageRequestConvertible |
An image request. |
queue | DispatchQueue? |
A queue on which to execute |
progress | ((_ response: ImageResponse?, _ completed: Int64, _ total: Int64) -> Void)? |
A closure to be called periodically on the main thread when the progress is updated. |
completion | @escaping ((_ result: Result<ImageResponse, Error>) -> Void) |
A closure to be called on the main thread when the request is finished. |
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
Name | Type | Description |
---|---|---|
request | ImageRequestConvertible |
An image request. |
loadData(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.
loadData(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
Name | Type | Description |
---|---|---|
request | ImageRequestConvertible |
An image request. |
queue | DispatchQueue? |
A queue on which to execute |
progress | ((_ completed: Int64, _ total: Int64) -> Void)? |
A closure to be called periodically on the main thread when the progress is updated. |
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
Name | Type | Description |
---|---|---|
request | ImageRequestConvertible |
An image request. |