-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathSDWebImageManager+loadImage.swift
More file actions
33 lines (30 loc) · 1.03 KB
/
SDWebImageManager+loadImage.swift
File metadata and controls
33 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
// SDWebImageManager+loadImage.swift
// NitroWebImage
//
// Created by Marc Rousavy on 30.06.25.
//
import Foundation
import SDWebImage
import NitroModules
extension SDWebImageManager {
func loadImage(with url: URL, options: AsyncImageLoadOptions?) async throws -> UIImage {
let webImageOptions = options?.toSDWebImageOptions() ?? []
let webImageContext = options?.toSDWebImageContext() ?? [:]
return try await withUnsafeThrowingContinuation { continuation in
self.loadImage(with: url, options: webImageOptions, context: webImageContext) { current, total, url in
print("\(url): Loaded \(current)/\(total) bytes")
} completed: { image, data, error, cacheType, finished, url in
if let image {
continuation.resume(returning: image)
} else {
if let error {
continuation.resume(throwing: error)
} else {
continuation.resume(throwing: RuntimeError.error(withMessage: "No Image or error was returned!"))
}
}
}
}
}
}