Explorar el Código

Unify API usage to resource protocol

onevcat hace 9 años
padre
commit
90cb57f38e

+ 3 - 3
Sources/ImageCache.swift

@@ -518,12 +518,12 @@ extension ImageCache {
      image is found either in memory or on disk. Essentially as long as there is a cache of the image somewhere
      true is returned. A convenience method that decodes `isImageCachedForKey`.
      
-     - parameter url: The image URL.
+     - parameter resource: The target resource. 
+       `cacheKey` property of this resource will be used to check whether this image be cached or not.
      
      - returns: True if the image is cached, false otherwise.
      */
-    public func cachedImageExists(for url: URL) -> Bool {
-        let resource = ImageResource(downloadURL: url)
+    public func cachedImageExists(for resource: Resource) -> Bool {
         let result = isImageCachedForKey(resource.cacheKey)
         return result.cached
     }

+ 1 - 1
Sources/ImagePrefetcher.swift

@@ -97,7 +97,7 @@ public class ImagePrefetcher {
                    progressBlock: PrefetcherProgressBlock? = nil,
                completionHandler: PrefetcherCompletionHandler? = nil)
     {
-        let resources: [Resource] = urls.map { ImageResource(downloadURL: $0) }
+        let resources: [Resource] = urls.map { $0 }
         self.init(resources: resources, optionsInfo: optionsInfo, progressBlock: progressBlock, completionHandler: completionHandler)
     }
     

+ 7 - 37
Sources/ImageView+Kingfisher.swift

@@ -42,37 +42,7 @@ public typealias IndicatorView = UIActivityIndicatorView
 extension ImageView {
 
     /**
-     Set an image with a URL, a placeholder image, options, progress handler and completion handler.
-     
-     - parameter url:               The URL of image.
-     - parameter placeholderImage:  A placeholder image when retrieving the image at URL.
-     - parameter optionsInfo:       A dictionary could control some behaviors. See `KingfisherOptionsInfo` for more.
-     - parameter progressBlock:     Called when the image downloading progress gets updated.
-     - parameter completionHandler: Called when the image retrieved and set.
-     
-     - returns: A task represents the retrieving process.
-     
-     - note: Both the `progressBlock` and `completionHandler` will be invoked in main thread.
-     The `CallbackDispatchQueue` specified in `optionsInfo` will not be used in callbacks of this method.
-     */
-    @discardableResult
-    public func kf_setImageWithURL(_ url: URL?,
-                                   placeholderImage: Image? = nil,
-                                   optionsInfo: KingfisherOptionsInfo? = nil,
-                                   progressBlock: DownloadProgressBlock? = nil,
-                                   completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
-    {
-        let resource = url.map { ImageResource(downloadURL: $0) }
-        return kf_setImageWithResource(resource,
-                                       placeholderImage: placeholderImage,
-                                       optionsInfo: optionsInfo,
-                                       progressBlock: progressBlock,
-                                       completionHandler: completionHandler)
-    }
-    
-    
-    /**
-    Set an image with a URL, a placeholder image, options, progress handler and completion handler.
+    Set an image with a resource, a placeholder image, options, progress handler and completion handler.
     
     - parameter resource:          Resource object contains information such as `cacheKey` and `downloadURL`.
     - parameter placeholderImage:  A placeholder image when retrieving the image at URL.
@@ -86,11 +56,11 @@ extension ImageView {
      The `CallbackDispatchQueue` specified in `optionsInfo` will not be used in callbacks of this method.
     */
     @discardableResult
-    public func kf_setImageWithResource(_ resource: Resource?,
-                                placeholderImage: Image? = nil,
-                                     optionsInfo: KingfisherOptionsInfo? = nil,
-                                   progressBlock: DownloadProgressBlock? = nil,
-                               completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
+    public func kf_setImage(with resource: Resource?,
+                         placeholderImage: Image? = nil,
+                              optionsInfo: KingfisherOptionsInfo? = nil,
+                            progressBlock: DownloadProgressBlock? = nil,
+                        completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
     {
         image = placeholderImage
         
@@ -114,7 +84,7 @@ extension ImageView {
             options.append(.preloadAllGIFData)
         }
 
-        let task = KingfisherManager.shared.retrieveImageWithResource(resource, optionsInfo: options,
+        let task = KingfisherManager.shared.retrieveImage(with: resource, optionsInfo: options,
             progressBlock: { receivedSize, totalSize in
                 if let progressBlock = progressBlock {
                     progressBlock(receivedSize: receivedSize, totalSize: totalSize)

+ 2 - 2
Sources/KingfisherManager.swift

@@ -111,7 +111,7 @@ public class KingfisherManager {
     - returns: A `RetrieveImageTask` task object. You can use this object to cancel the task.
     */
     @discardableResult
-    public func retrieveImageWithResource(_ resource: Resource,
+    public func retrieveImage(with resource: Resource,
         optionsInfo: KingfisherOptionsInfo?,
         progressBlock: DownloadProgressBlock?,
         completionHandler: CompletionHandler?) -> RetrieveImageTask
@@ -160,7 +160,7 @@ public class KingfisherManager {
                            progressBlock: DownloadProgressBlock?,
                        completionHandler: CompletionHandler?) -> RetrieveImageTask
     {
-        return retrieveImageWithResource(ImageResource(downloadURL: url), optionsInfo: optionsInfo, progressBlock: progressBlock, completionHandler: completionHandler)
+        return retrieveImage(with: ImageResource(downloadURL: url), optionsInfo: optionsInfo, progressBlock: progressBlock, completionHandler: completionHandler)
     }
     
     @discardableResult

+ 14 - 74
Sources/NSButton+Kingfisher.swift

@@ -34,37 +34,7 @@ import AppKit
 extension NSButton {
 
     /**
-     Set an image with a URL, a placeholder image, options, progress handler and completion handler.
-
-     - parameter URL:               The URL of image.
-     - parameter placeholderImage:  A placeholder image when retrieving the image at URL.
-     - parameter optionsInfo:       A dictionary could control some behaviors. See `KingfisherOptionsInfo` for more.
-     - parameter progressBlock:     Called when the image downloading progress gets updated.
-     - parameter completionHandler: Called when the image retrieved and set.
-
-     - returns: A task represents the retrieving process.
-
-     - note: Both the `progressBlock` and `completionHandler` will be invoked in main thread.
-     The `CallbackDispatchQueue` specified in `optionsInfo` will not be used in callbacks of this method.
-     */
-    @discardableResult
-    public func kf_setImageWithURL(_ URL: URL?,
-                                   placeholderImage: Image? = nil,
-                                   optionsInfo: KingfisherOptionsInfo? = nil,
-                                   progressBlock: DownloadProgressBlock? = nil,
-                                   completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
-    {
-        let resource = URL.map { ImageResource(downloadURL: $0) }
-        return kf_setImageWithResource(resource,
-                                       placeholderImage: placeholderImage,
-                                       optionsInfo: optionsInfo,
-                                       progressBlock: progressBlock,
-                                       completionHandler: completionHandler)
-    }
-
-
-    /**
-     Set an image with a URL, a placeholder image, options, progress handler and completion handler.
+     Set an image with a resource, a placeholder image, options, progress handler and completion handler.
 
      - parameter resource:          Resource object contains information such as `cacheKey` and `downloadURL`.
      - parameter placeholderImage:  A placeholder image when retrieving the image at URL.
@@ -78,11 +48,11 @@ extension NSButton {
      The `CallbackDispatchQueue` specified in `optionsInfo` will not be used in callbacks of this method.
      */
     @discardableResult
-    public func kf_setImageWithResource(_ resource: Resource?,
-                                        placeholderImage: Image? = nil,
-                                        optionsInfo: KingfisherOptionsInfo? = nil,
-                                        progressBlock: DownloadProgressBlock? = nil,
-                                        completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
+    public func kf_setImage(with resource: Resource?,
+                         placeholderImage: Image? = nil,
+                              optionsInfo: KingfisherOptionsInfo? = nil,
+                            progressBlock: DownloadProgressBlock? = nil,
+                        completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
     {
         image = placeholderImage
         
@@ -92,7 +62,7 @@ extension NSButton {
         }
         
         kf_setWebURL(resource.downloadURL)
-        let task = KingfisherManager.shared.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
+        let task = KingfisherManager.shared.retrieveImage(with: resource, optionsInfo: optionsInfo,
              progressBlock: { receivedSize, totalSize in
                 if let progressBlock = progressBlock {
                     progressBlock(receivedSize: receivedSize, totalSize: totalSize)
@@ -150,37 +120,7 @@ extension NSButton {
 extension NSButton {
 
     /**
-     Set an alternateImage with a URL, a placeholder image, options, progress handler and completion handler.
-
-     - parameter URL:               The URL of image.
-     - parameter placeholderImage:  A placeholder image when retrieving the image at URL.
-     - parameter optionsInfo:       A dictionary could control some behaviors. See `KingfisherOptionsInfo` for more.
-     - parameter progressBlock:     Called when the image downloading progress gets updated.
-     - parameter completionHandler: Called when the image retrieved and set.
-
-     - returns: A task represents the retrieving process.
-
-     - note: Both the `progressBlock` and `completionHandler` will be invoked in main thread.
-     The `CallbackDispatchQueue` specified in `optionsInfo` will not be used in callbacks of this method.
-     */
-    @discardableResult
-    public func kf_setAlternateImageWithURL(_ URL: URL?,
-                                            placeholderImage: Image? = nil,
-                                            optionsInfo: KingfisherOptionsInfo? = nil,
-                                            progressBlock: DownloadProgressBlock? = nil,
-                                            completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
-    {
-        let resource = URL.map { ImageResource(downloadURL: $0) }
-        return kf_setAlternateImageWithResource(resource,
-                                                placeholderImage: placeholderImage,
-                                                optionsInfo: optionsInfo,
-                                                progressBlock: progressBlock,
-                                                completionHandler: completionHandler)
-    }
-
-
-    /**
-     Set an alternateImage with a URL, a placeholder image, options, progress handler and completion handler.
+     Set an alternateImage with a resource, a placeholder image, options, progress handler and completion handler.
 
      - parameter resource:          Resource object contains information such as `cacheKey` and `downloadURL`.
      - parameter placeholderImage:  A placeholder image when retrieving the image at URL.
@@ -194,11 +134,11 @@ extension NSButton {
      The `CallbackDispatchQueue` specified in `optionsInfo` will not be used in callbacks of this method.
      */
     @discardableResult
-    public func kf_setAlternateImageWithResource(_ resource: Resource?,
-                                                 placeholderImage: Image? = nil,
-                                                 optionsInfo: KingfisherOptionsInfo? = nil,
-                                                 progressBlock: DownloadProgressBlock? = nil,
-                                                 completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
+    public func kf_setAlternateImage(with resource: Resource?,
+                                  placeholderImage: Image? = nil,
+                                       optionsInfo: KingfisherOptionsInfo? = nil,
+                                     progressBlock: DownloadProgressBlock? = nil,
+                                 completionHandler: CompletionHandler? = nil) -> RetrieveImageTask
     {
         alternateImage = placeholderImage
         
@@ -208,7 +148,7 @@ extension NSButton {
         }
         
         kf_setAlternateWebURL(resource.downloadURL)
-        let task = KingfisherManager.shared.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
+        let task = KingfisherManager.shared.retrieveImage(with: resource, optionsInfo: optionsInfo,
              progressBlock: { receivedSize, totalSize in
                 if let progressBlock = progressBlock {
                     progressBlock(receivedSize: receivedSize, totalSize: totalSize)

+ 5 - 0
Sources/Resource.swift

@@ -60,3 +60,8 @@ public struct ImageResource: Resource {
         self.cacheKey = cacheKey ?? downloadURL.absoluteString
     }
 }
+
+extension URL: Resource {
+    public var cacheKey: String { return absoluteString }
+    public var downloadURL: URL { return self }
+}

+ 2 - 2
Sources/UIButton+Kingfisher.swift

@@ -94,7 +94,7 @@ extension UIButton {
         }
         
         kf_setWebURL(resource.downloadURL as URL, forState: state)
-        let task = KingfisherManager.shared.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
+        let task = KingfisherManager.shared.retrieveImage(with: resource, optionsInfo: optionsInfo,
             progressBlock: { receivedSize, totalSize in
                 if let progressBlock = progressBlock {
                     progressBlock(receivedSize: receivedSize, totalSize: totalSize)
@@ -233,7 +233,7 @@ extension UIButton {
         }
         
         kf_setBackgroundWebURL(resource.downloadURL as URL, forState: state)
-        let task = KingfisherManager.shared.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
+        let task = KingfisherManager.shared.retrieveImage(with: resource, optionsInfo: optionsInfo,
             progressBlock: { receivedSize, totalSize in
                 if let progressBlock = progressBlock {
                     progressBlock(receivedSize: receivedSize, totalSize: totalSize)

+ 32 - 32
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -64,11 +64,11 @@ class ImageViewExtensionTests: XCTestCase {
         
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
         var progressBlockIsCalled = false
         
-        imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             progressBlockIsCalled = true
             XCTAssertTrue(Thread.isMainThread)
         }) { (image, error, cacheType, imageURL) -> () in
@@ -92,10 +92,10 @@ class ImageViewExtensionTests: XCTestCase {
         
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
         let customQueue = DispatchQueue(label: "com.kingfisher.testQueue")
-        imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: [.callbackDispatchQueue(customQueue)], progressBlock: { (receivedSize, totalSize) -> () in
+        imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: [.callbackDispatchQueue(customQueue)], progressBlock: { (receivedSize, totalSize) -> () in
             XCTAssertTrue(Thread.isMainThread)
         }) { (image, error, cacheType, imageURL) -> () in
             XCTAssertTrue(Thread.isMainThread, "The image extension callback should be always in main queue.")
@@ -117,7 +117,7 @@ class ImageViewExtensionTests: XCTestCase {
         
         cleanDefaultCache()
         
-        _ = imageView.kf_setImageWithResource(resource, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        _ = imageView.kf_setImage(with: resource, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             progressBlockIsCalled = true
             }) { (image, error, cacheType, imageURL) -> () in
                 expectation.fulfill()
@@ -139,12 +139,12 @@ class ImageViewExtensionTests: XCTestCase {
 
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
         var progressBlockIsCalled = false
         var completionBlockIsCalled = false
         
-        let task = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let task = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             progressBlockIsCalled = true
         }) { (image, error, cacheType, imageURL) -> () in
             completionBlockIsCalled = true
@@ -166,14 +166,14 @@ class ImageViewExtensionTests: XCTestCase {
         
         let URLString = testKeys[0]
         let stub = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)?.delay()
-        let URL = Foundation.URL(string: URLString)!
+        let url = Foundation.URL(string: URLString)!
         
         var progressBlockIsCalled = false
         var completionBlockIsCalled = false
         
         cleanDefaultCache()
         
-        let task = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let task = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             progressBlockIsCalled = true
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(error)
@@ -200,26 +200,26 @@ class ImageViewExtensionTests: XCTestCase {
         
         let URLString = testKeys[0]
         let stub = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)?.delay()
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
         var task1Completion = false
         var task2Completion = false
         var task3Completion = false
         
-        let task1 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let task1 = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
 
             }) { (image, error, cacheType, imageURL) -> () in
                 task1Completion = true
         }
         
-        let _ = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let _ = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(image)
                 task2Completion = true
         }
         
-        let _ = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let _ = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(image)
@@ -246,27 +246,27 @@ class ImageViewExtensionTests: XCTestCase {
         
         let URLString = testKeys[0]
         let stub = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)?.delay()
-        let URL = Foundation.URL(string: URLString)!
+        let url = Foundation.URL(string: URLString)!
         
         var task1Completion = false
         var task2Completion = false
         var task3Completion = false
         
-        let task1 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let task1 = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(image)
                 task1Completion = true
         }
         
-        let _ = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let _ = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(image)
                 task2Completion = true
         }
         
-        let _ = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let _ = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(image)
@@ -293,13 +293,13 @@ class ImageViewExtensionTests: XCTestCase {
         
         let URLString = testKeys[0]
         let stub = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)?.delay()
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
         var task1Completion = false
         var task2Completion = false
         var task3Completion = false
         
-        let task1 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let task1 = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(error)
@@ -307,7 +307,7 @@ class ImageViewExtensionTests: XCTestCase {
                 task1Completion = true
         }
         
-        let task2 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let task2 = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(error)
@@ -315,7 +315,7 @@ class ImageViewExtensionTests: XCTestCase {
                 task2Completion = true
         }
         
-        let task3 = imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let task3 = imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(error)
@@ -352,9 +352,9 @@ class ImageViewExtensionTests: XCTestCase {
         
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
-        imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: [.targetCache(cache1)], progressBlock: { (receivedSize, totalSize) -> () in
+        imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: [.targetCache(cache1)], progressBlock: { (receivedSize, totalSize) -> () in
             
         }) { (image, error, cacheType, imageURL) -> () in
             
@@ -362,7 +362,7 @@ class ImageViewExtensionTests: XCTestCase {
             XCTAssertFalse(cache2.isImageCachedForKey(URLString).cached, "This image should not be cached in cache2.")
             XCTAssertFalse(KingfisherManager.shared.cache.isImageCachedForKey(URLString).cached, "This image should not be cached in default cache.")
             
-            self.imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: [.targetCache(cache2)], progressBlock: { (receivedSize, totalSize) -> () in
+            self.imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: [.targetCache(cache2)], progressBlock: { (receivedSize, totalSize) -> () in
                 
             }, completionHandler: { (image, error, cacheType, imageURL) -> () in
                 
@@ -397,9 +397,9 @@ class ImageViewExtensionTests: XCTestCase {
         
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
-        imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             let indicator = self.imageView.kf_indicator
             XCTAssertNotNil(indicator, "The indicator view should exist when showIndicatorWhenLoading is true")
@@ -419,9 +419,9 @@ class ImageViewExtensionTests: XCTestCase {
         
         let URLString = testKeys[0]
         let stub = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)?.delay()
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
-        imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
                 XCTFail("Progress block should not be called.")
             }) { (image, error, cacheType, imageURL) -> () in
                 XCTAssertNotNil(error)
@@ -449,7 +449,7 @@ class ImageViewExtensionTests: XCTestCase {
         var task1Complete = false
         var task2Complete = false
         
-        imageView.kf_setImageWithURL(URLs[0], placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        imageView.kf_setImage(with: URLs[0], placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 task1Complete = true
@@ -458,7 +458,7 @@ class ImageViewExtensionTests: XCTestCase {
                 XCTAssertNotEqual(self.imageView.image, image)
         }
         
-        self.imageView.kf_setImageWithURL(URLs[1], placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        self.imageView.kf_setImage(with: URLs[1], placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
             }) { (image, error, cacheType, imageURL) -> () in
                 task2Complete = true
@@ -480,8 +480,8 @@ class ImageViewExtensionTests: XCTestCase {
     func testSettingNilURL() {
         let expectation = self.expectation(description: "wait for downloading image")
         
-        let URL: Foundation.URL? = nil
-        imageView.kf_setImageWithURL(URL, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let url: URL? = nil
+        imageView.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             XCTFail("Progress block should not be called.")
         }) { (image, error, cacheType, imageURL) -> () in
             XCTAssertNil(image)

+ 5 - 5
Tests/KingfisherTests/NSButtonExtensionTests.swift

@@ -71,7 +71,7 @@ class NSButtonExtensionTests: XCTestCase {
 
         cleanDefaultCache()
 
-        button.kf_setImageWithURL(url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        button.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             progressBlockIsCalled = true
         }) { (image, error, cacheType, imageURL) -> () in
             expectation.fulfill()
@@ -94,7 +94,7 @@ class NSButtonExtensionTests: XCTestCase {
         let url = URL(string: URLString)!
 
         var progressBlockIsCalled = false
-        button.kf_setAlternateImageWithURL(url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        button.kf_setAlternateImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             progressBlockIsCalled = true
         }) { (image, error, cacheType, imageURL) -> () in
             expectation.fulfill()
@@ -117,7 +117,7 @@ class NSButtonExtensionTests: XCTestCase {
         let stub = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)?.delay()
         let url = URL(string: URLString)!
 
-        button.kf_setImageWithURL(url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        button.kf_setImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             XCTFail("Progress block should not be called.")
         }) { (image, error, cacheType, imageURL) -> () in
             XCTAssertNotNil(error)
@@ -141,7 +141,7 @@ class NSButtonExtensionTests: XCTestCase {
         let stub = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)?.delay()
         let url = URL(string: URLString)!
 
-        _ = button.kf_setAlternateImageWithURL(url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        _ = button.kf_setAlternateImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             XCTFail("Progress block should not be called.")
         }) { (image, error, cacheType, imageURL) -> () in
             XCTAssertNotNil(error)
@@ -162,7 +162,7 @@ class NSButtonExtensionTests: XCTestCase {
         let expectation = self.expectation(description: "wait for downloading image")
         
         let url: URL? = nil
-        button.kf_setAlternateImageWithURL(url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        button.kf_setAlternateImage(with: url, placeholderImage: nil, optionsInfo: nil, progressBlock: { (receivedSize, totalSize) -> () in
             XCTFail("Progress block should not be called.")
         }) { (image, error, cacheType, imageURL) -> () in
             XCTAssertNil(image)