Sfoglia il codice sorgente

Rename ImageResource to KF.ImageResource

onevcat 2 anni fa
parent
commit
a895c4c7e1

+ 1 - 1
Demo/Demo/Kingfisher-Demo/ViewControllers/HighResolutionCollectionViewController.swift

@@ -62,7 +62,7 @@ class HighResolutionCollectionViewController: UICollectionViewController {
         // this demo. Normally you can just use the URL to set image.
 
         // This should crash most devices due to memory pressure.
-        // let resource = ImageResource(downloadURL: url, cacheKey: "\(url.absoluteString)-\(indexPath.row)")
+        // let resource = KF.ImageResource(downloadURL: url, cacheKey: "\(url.absoluteString)-\(indexPath.row)")
         // imageView.kf.setImage(with: resource)
 
         // This would survive on even the lowest spec devices!

+ 1 - 1
Demo/Demo/Kingfisher-Demo/ViewControllers/InfinityCollectionViewController.swift

@@ -52,7 +52,7 @@ class InfinityCollectionViewController: UICollectionViewController {
         let url = urls[indexPath.row % urls.count]
 
         // Mark each row as a new image.
-        let resource = ImageResource(downloadURL: url, cacheKey: "key-\(indexPath.row)")
+        let resource = KF.ImageResource(downloadURL: url, cacheKey: "key-\(indexPath.row)")
         KF.resource(resource).set(to: cell.cellImageView)
 
         return cell

+ 28 - 22
Sources/General/ImageSource/Resource.swift

@@ -47,35 +47,41 @@ extension Resource {
         let key = overrideCacheKey ?? cacheKey
         return downloadURL.isFileURL ?
             .provider(LocalFileImageDataProvider(fileURL: downloadURL, cacheKey: key)) :
-            .network(ImageResource(downloadURL: downloadURL, cacheKey: key))
+            .network(KF.ImageResource(downloadURL: downloadURL, cacheKey: key))
     }
 }
 
-/// ImageResource is a simple combination of `downloadURL` and `cacheKey`.
-/// When passed to image view set methods, Kingfisher will try to download the target
-/// image from the `downloadURL`, and then store it with the `cacheKey` as the key in cache.
-public struct ImageResource: Resource {
+@available(*, deprecated, message: "This type conflicts with `GeneratedAssetSymbols.ImageResource` in Swift 5.9. Renamed to avoid issues in the future.", renamed: "KF.ImageResource")
+public typealias ImageResource = KF.ImageResource
 
-    // MARK: - Initializers
 
-    /// Creates an image resource.
-    ///
-    /// - Parameters:
-    ///   - downloadURL: The target image URL from where the image can be downloaded.
-    ///   - cacheKey: The cache key. If `nil`, Kingfisher will use the `absoluteString` of `downloadURL` as the key.
-    ///               Default is `nil`.
-    public init(downloadURL: URL, cacheKey: String? = nil) {
-        self.downloadURL = downloadURL
-        self.cacheKey = cacheKey ?? downloadURL.cacheKey
-    }
+extension KF {
+    /// ImageResource is a simple combination of `downloadURL` and `cacheKey`.
+    /// When passed to image view set methods, Kingfisher will try to download the target
+    /// image from the `downloadURL`, and then store it with the `cacheKey` as the key in cache.
+    public struct ImageResource: Resource {
 
-    // MARK: Protocol Conforming
-    
-    /// The key used in cache.
-    public let cacheKey: String
+        // MARK: - Initializers
 
-    /// The target image URL.
-    public let downloadURL: URL
+        /// Creates an image resource.
+        ///
+        /// - Parameters:
+        ///   - downloadURL: The target image URL from where the image can be downloaded.
+        ///   - cacheKey: The cache key. If `nil`, Kingfisher will use the `absoluteString` of `downloadURL` as the key.
+        ///               Default is `nil`.
+        public init(downloadURL: URL, cacheKey: String? = nil) {
+            self.downloadURL = downloadURL
+            self.cacheKey = cacheKey ?? downloadURL.cacheKey
+        }
+
+        // MARK: Protocol Conforming
+        
+        /// The key used in cache.
+        public let cacheKey: String
+
+        /// The target image URL.
+        public let downloadURL: URL
+    }
 }
 
 /// URL conforms to `Resource` in Kingfisher.

+ 1 - 1
Tests/KingfisherTests/ImageDataProviderTests.swift

@@ -136,7 +136,7 @@ class ImageDataProviderTests: XCTestCase {
     
     func testLocalFileExplicitKey() {
         let url1 = URL(string: "file:///Users/onevcat/Library/Developer/CoreSimulator/Devices/ABC/data/Containers/Bundle/Application/DEF/Kingfisher-Demo.app/images/kingfisher-1.jpg")!
-        let imageResource = ImageResource(downloadURL: url1, cacheKey: "hello")
+        let imageResource = KF.ImageResource(downloadURL: url1, cacheKey: "hello")
         let source = imageResource.convertToSource()
         XCTAssertEqual(source.cacheKey, "hello")
     }

+ 1 - 1
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -114,7 +114,7 @@ class ImageViewExtensionTests: XCTestCase {
 
         var progressBlockIsCalled = false
 
-        let resource = ImageResource(downloadURL: url)
+        let resource = KF.ImageResource(downloadURL: url)
         imageView.kf.setImage(
             with: resource,
             progressBlock: { _, _ in progressBlockIsCalled = true })