|
|
@@ -48,7 +48,7 @@ public enum KF {
|
|
|
/// - Parameter source: The `Source` object defines data information from network or a data provider.
|
|
|
/// - Returns: A `KF.Builder` for future configuration. After configuring the builder, call `set(to:)`
|
|
|
/// to start the image loading.
|
|
|
- public static func source(_ source: Source) -> KF.Builder {
|
|
|
+ public static func source(_ source: Source?) -> KF.Builder {
|
|
|
Builder(source: source)
|
|
|
}
|
|
|
|
|
|
@@ -56,8 +56,8 @@ public enum KF {
|
|
|
/// - Parameter resource: The `Resource` object defines data information like key or URL.
|
|
|
/// - Returns: A `KF.Builder` for future configuration. After configuring the builder, call `set(to:)`
|
|
|
/// to start the image loading.
|
|
|
- public static func resource(_ resource: Resource) -> KF.Builder {
|
|
|
- Builder(source: .network(resource))
|
|
|
+ public static func resource(_ resource: Resource?) -> KF.Builder {
|
|
|
+ source(resource?.convertToSource())
|
|
|
}
|
|
|
|
|
|
/// Creates a builder for a given `URL` and an optional cache key.
|
|
|
@@ -67,16 +67,16 @@ public enum KF {
|
|
|
/// If `nil`, the `absoluteString` of `url` is used as the cache key.
|
|
|
/// - Returns: A `KF.Builder` for future configuration. After configuring the builder, call `set(to:)`
|
|
|
/// to start the image loading.
|
|
|
- public static func url(_ url: URL, cacheKey: String? = nil) -> KF.Builder {
|
|
|
- Builder(source: .network(ImageResource(downloadURL: url, cacheKey: cacheKey)))
|
|
|
+ public static func url(_ url: URL?, cacheKey: String? = nil) -> KF.Builder {
|
|
|
+ source(url?.convertToSource(overrideCacheKey: cacheKey))
|
|
|
}
|
|
|
|
|
|
/// Creates a builder for a given `ImageDataProvider`.
|
|
|
/// - Parameter provider: The `ImageDataProvider` object contains information about the data.
|
|
|
/// - Returns: A `KF.Builder` for future configuration. After configuring the builder, call `set(to:)`
|
|
|
/// to start the image loading.
|
|
|
- public static func dataProvider(_ provider: ImageDataProvider) -> KF.Builder {
|
|
|
- Builder(source: .provider(provider))
|
|
|
+ public static func dataProvider(_ provider: ImageDataProvider?) -> KF.Builder {
|
|
|
+ source(provider?.convertToSource())
|
|
|
}
|
|
|
|
|
|
/// Creates a builder for some given raw data and a cache key.
|
|
|
@@ -85,8 +85,12 @@ public enum KF {
|
|
|
/// - cacheKey: The key used to store the downloaded image in cache.
|
|
|
/// - Returns: A `KF.Builder` for future configuration. After configuring the builder, call `set(to:)`
|
|
|
/// to start the image loading.
|
|
|
- public static func data(_ data: Data, cacheKey: String) -> KF.Builder {
|
|
|
- Builder(source: .provider(RawImageDataProvider(data: data, cacheKey: cacheKey)))
|
|
|
+ public static func data(_ data: Data?, cacheKey: String) -> KF.Builder {
|
|
|
+ if let data = data {
|
|
|
+ return dataProvider(RawImageDataProvider(data: data, cacheKey: cacheKey))
|
|
|
+ } else {
|
|
|
+ return dataProvider(nil)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -95,7 +99,7 @@ extension KF {
|
|
|
|
|
|
/// A builder class to configure an image retrieving task and set it to a holder view or component.
|
|
|
public class Builder {
|
|
|
- private let source: Source
|
|
|
+ private let source: Source?
|
|
|
|
|
|
#if os(watchOS)
|
|
|
private var placeholder: KFCrossPlatformImage?
|
|
|
@@ -109,7 +113,7 @@ extension KF {
|
|
|
public let onSuccessDelegate = Delegate<RetrieveImageResult, Void>()
|
|
|
public let onProgressDelegate = Delegate<(Int64, Int64), Void>()
|
|
|
|
|
|
- init(source: Source) {
|
|
|
+ init(source: Source?) {
|
|
|
self.source = source
|
|
|
}
|
|
|
|