|
@@ -35,7 +35,6 @@ public typealias DownloadProgressBlock = ((_ receivedSize: Int64, _ totalSize: I
|
|
|
|
|
|
|
|
/// Represents the result of a Kingfisher retrieving image task.
|
|
/// Represents the result of a Kingfisher retrieving image task.
|
|
|
public struct RetrieveImageResult {
|
|
public struct RetrieveImageResult {
|
|
|
-
|
|
|
|
|
/// Gets the image object of this result.
|
|
/// Gets the image object of this result.
|
|
|
public let image: KFCrossPlatformImage
|
|
public let image: KFCrossPlatformImage
|
|
|
|
|
|
|
@@ -50,6 +49,17 @@ public struct RetrieveImageResult {
|
|
|
/// When an alternative source loading happened, the `source` will be the replacing loading target, while the
|
|
/// When an alternative source loading happened, the `source` will be the replacing loading target, while the
|
|
|
/// `originalSource` will be kept as the initial `source` which issued the image loading process.
|
|
/// `originalSource` will be kept as the initial `source` which issued the image loading process.
|
|
|
public let originalSource: Source
|
|
public let originalSource: Source
|
|
|
|
|
+
|
|
|
|
|
+ /// Gets the data behind the result.
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// If this result is from a network downloading (when `cacheType == .none`), calling this returns the downloaded
|
|
|
|
|
+ /// data. If the reuslt is from cache, it serializes the image with the given cache serializer in the loading option
|
|
|
|
|
+ /// and returns the result.
|
|
|
|
|
+ ///
|
|
|
|
|
+ /// - Note:
|
|
|
|
|
+ /// This can be a time-consuming action, so if you need to use the data for multiple times, it is suggested to hold
|
|
|
|
|
+ /// it and prevent keeping calling this too frequently.
|
|
|
|
|
+ public let data: () -> Data?
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// A struct that stores some related information of an `KingfisherError`. It provides some context information for
|
|
/// A struct that stores some related information of an `KingfisherError`. It provides some context information for
|
|
@@ -419,7 +429,8 @@ public class KingfisherManager {
|
|
|
image: options.imageModifier?.modify(value.image) ?? value.image,
|
|
image: options.imageModifier?.modify(value.image) ?? value.image,
|
|
|
cacheType: .none,
|
|
cacheType: .none,
|
|
|
source: source,
|
|
source: source,
|
|
|
- originalSource: context.originalSource
|
|
|
|
|
|
|
+ originalSource: context.originalSource,
|
|
|
|
|
+ data: { value.originalData }
|
|
|
)
|
|
)
|
|
|
// Add image to cache.
|
|
// Add image to cache.
|
|
|
let targetCache = options.targetCache ?? self.cache
|
|
let targetCache = options.targetCache ?? self.cache
|
|
@@ -561,7 +572,8 @@ public class KingfisherManager {
|
|
|
image: image,
|
|
image: image,
|
|
|
cacheType: $0.cacheType,
|
|
cacheType: $0.cacheType,
|
|
|
source: source,
|
|
source: source,
|
|
|
- originalSource: context.originalSource
|
|
|
|
|
|
|
+ originalSource: context.originalSource,
|
|
|
|
|
+ data: { options.cacheSerializer.data(with: image, original: nil) }
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
@@ -624,11 +636,13 @@ public class KingfisherManager {
|
|
|
let coordinator = CacheCallbackCoordinator(
|
|
let coordinator = CacheCallbackCoordinator(
|
|
|
shouldWaitForCache: options.waitForCache, shouldCacheOriginal: false)
|
|
shouldWaitForCache: options.waitForCache, shouldCacheOriginal: false)
|
|
|
|
|
|
|
|
|
|
+ let image = options.imageModifier?.modify(processedImage) ?? processedImage
|
|
|
let result = RetrieveImageResult(
|
|
let result = RetrieveImageResult(
|
|
|
- image: options.imageModifier?.modify(processedImage) ?? processedImage,
|
|
|
|
|
|
|
+ image: image,
|
|
|
cacheType: .none,
|
|
cacheType: .none,
|
|
|
source: source,
|
|
source: source,
|
|
|
- originalSource: context.originalSource
|
|
|
|
|
|
|
+ originalSource: context.originalSource,
|
|
|
|
|
+ data: { options.cacheSerializer.data(with: processedImage, original: nil) }
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
targetCache.store(
|
|
targetCache.store(
|