Nuke Documentation

Class Fetch​Image

@available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
public final class FetchImage: ObservableObject, Identifiable  

An observable object that simplifies image loading in SwiftUI.

FetchImage FetchImage Identifiable Identifiable FetchImage->Identifiable ObservableObject ObservableObject FetchImage->ObservableObject

Nested Types

FetchImage.Progress

The download progress.

Conforms To

Identifiable
ObservableObject

Initializers

init()

public init()  

Properties

result

@Published public private(set) var result: Result<ImageResponse, Error>? 

Returns the current fetch result.

image

public var image: PlatformImage?  

Returns the fetched image.

image​Container

@Published public private(set) var imageContainer: ImageContainer? 

Returns the fetched image.

is​Loading

@Published public private(set) var isLoading: Bool = false

Returns true if the image is being loaded.

animation

public var animation: Animation? 

Animations to be used when displaying the loaded images. By default, nil.

progress

@Published public private(set) var progress  

The progress of the image download.

priority

public var priority: ImageRequest.Priority?  

Updates the priority of the task, even if the task is already running. nil by default

on​Start

public var onStart: ((_ task: ImageTask) -> Void)? 

Gets called when the request is started.

on​Progress

public var onProgress: ((_ response: ImageResponse?, _ completed: Int64, _ total: Int64) -> Void)? 

Gets called when the request progress is updated.

on​Success

public var onSuccess: ((_ response: ImageResponse) -> Void)? 

Gets called when the requests finished successfully.

on​Failure

public var onFailure: ((_ response: Error) -> Void)? 

Gets called when the requests fails.

on​Completion

public var onCompletion: ((_ result: Result<ImageResponse, Error>) -> Void)? 

Gets called when the request is completed.

pipeline

public var pipeline: ImagePipeline = .shared

processors

public var processors: [ImageProcessing]? 

Image processors to be applied unless the processors are provided in the request. nil by default.

view

public var view: SwiftUI.Image?  

Methods

load(_:​)

public func load(_ request: ImageRequestConvertible?)  

Loads an image with the given request.

load(_:​)

public func load<P: Publisher>(_ publisher: P) where P.Output == ImageResponse  

Loads an image with the given publisher.

cancel()

public func cancel()  

Marks the request as being cancelled. Continues to display a downloaded image.

reset()

public func reset()  

Resets the FetchImage instance by cancelling the request and removing all of the state including the loaded image.