ImageManager
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
public final class ImageManager : ObservableObject
extension ImageManager: IndicatorReportable
A Image observable object for handle image load process. This drive the Source of Truth for image loading status.
You can use @ObservedObject
to associate each instance of manager to your View type, which update your view’s body from SwiftUI framework when image was loaded.
-
loaded image, note when progressive loading, this will published multiple times with different partial image
Declaration
Swift
@Published public var image: PlatformImage? { get set }
-
loaded image data, may be nil if hit from memory cache. This will only published once even on incremental image loading
Declaration
Swift
@Published public var imageData: Data? { get set }
-
loaded image cache type, .none means from network
Declaration
Swift
@Published public var cacheType: SDImageCacheType { get set }
-
loading error, you can grab the error code and reason listed in
SDWebImageErrorDomain
, to provide a user interface about the error reasonDeclaration
Swift
@Published public var error: Error? { get set }
-
whether network is loading or cache is querying, should only be used for indicator binding
Declaration
Swift
@Published public var isLoading: Bool { get set }
-
network progress, should only be used for indicator binding
Declaration
Swift
@Published public var progress: Double { get set }
-
true means during incremental loading
Declaration
Swift
@Published public var isIncremental: Bool { get set }
-
Create a image manager for loading the specify url, with custom options and context.
Declaration
Swift
public init(url: URL?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]? = nil)
Parameters
url
The image url
options
The options to use when downloading the image. See
SDWebImageOptions
for the possible values.context
A context contains different options to perform specify changes or processes, see
SDWebImageContextOption
. This hold the extra objects whichoptions
enum can not hold. -
Start to load the url operation
Declaration
Swift
public func load()
-
Cancel the current url loading
Declaration
Swift
public func cancel()
-
loaded image, note when progressive loading, this will published multiple times with different partial image
Declaration
Swift
@Published public var image: PlatformImage? { get set }
-
Provide the action when image load fails.
Declaration
Swift
public func setOnFailure(perform action: ((Error) -> Void)? = nil)
Parameters
action
The action to perform. The first arg is the error during loading. If
action
isnil
, the call has no effect. -
Provide the action when image load successes.
Declaration
Swift
public func setOnSuccess(perform action: @escaping (PlatformImage) -> Void)
Parameters
action
The action to perform. The first arg is the loaded image. If
action
isnil
, the call has no effect. -
Provide the action when image load successes.
Declaration
Swift
public func setOnSuccess(perform action: @escaping (PlatformImage, SDImageCacheType) -> Void)
Parameters
action
The action to perform. The first arg is the loaded image, the second arg is the cache type loaded from. If
action
isnil
, the call has no effect. -
Provide the action when image load successes.
Declaration
Swift
public func setOnSuccess(perform action: ((PlatformImage, Data?, SDImageCacheType) -> Void)? = nil)
Parameters
action
The action to perform. The first arg is the loaded image, the second arg is the loaded image data, the third arg is the cache type loaded from. If
action
isnil
, the call has no effect. -
Provide the action when image load progress changes.
Declaration
Swift
public func setOnProgress(perform action: ((Int, Int) -> Void)? = nil)
Parameters
action
The action to perform. The first arg is the received size, the second arg is the total size, all in bytes. If
action
isnil
, the call has no effect. -
Provide the action when image load successes.
Declaration
Swift
public func setOnSuccess(perform action: @escaping (PlatformImage) -> Void)
Parameters
action
The action to perform. The first arg is the loaded image. If
action
isnil
, the call has no effect. -
Provide the action when image load successes.
Declaration
Swift
public func setOnSuccess(perform action: @escaping (PlatformImage, SDImageCacheType) -> Void)
Parameters
action
The action to perform. The first arg is the loaded image, the second arg is the cache type loaded from. If
action
isnil
, the call has no effect. -
Provide the action when image load successes.
Declaration
Swift
public func setOnSuccess(perform action: ((PlatformImage, Data?, SDImageCacheType) -> Void)? = nil)
Parameters
action
The action to perform. The first arg is the loaded image, the second arg is the loaded image data, the third arg is the cache type loaded from. If
action
isnil
, the call has no effect.