Class
FetchImage
@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.
Relationships
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.
imageContainer
@Published public private(set) var imageContainer: ImageContainer?
Returns the fetched image.
isLoading
@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
.
priority
public var priority: ImageRequest.Priority?
Updates the priority of the task, even if the task is already running.
nil
by default
onStart
public var onStart: ((_ task: ImageTask) -> Void)?
Gets called when the request is started.
onProgress
public var onProgress: ((_ response: ImageResponse?, _ completed: Int64, _ total: Int64) -> Void)?
Gets called when the request progress is updated.
onSuccess
public var onSuccess: ((_ response: ImageResponse) -> Void)?
Gets called when the requests finished successfully.
onFailure
public var onFailure: ((_ response: Error) -> Void)?
Gets called when the requests fails.
onCompletion
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. []
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.
load(_:)
@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.0, *)
public func load(_ action: @escaping () async throws -> ImageResponse)
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.