Browse Source

Kingfisher manager API adjust

onevcat 9 years ago
parent
commit
9f0b2b5145

+ 6 - 6
Sources/ImageCache.swift

@@ -202,7 +202,7 @@ extension ImageCache {
     - parameter fromDisk:          Whether this image should be removed from disk or not. If false, the image will be only removed from memory.
     - parameter completionHandler: Called when removal operation completes.
     */
-    public func removeImageForKey(_ key: String, fromDisk: Bool = true, completionHandler: (() -> Void)? = nil) {
+    public func removeImage(forKey key: String, fromDisk: Bool = true, completionHandler: (() -> Void)? = nil) {
         memoryCache.removeObject(forKey: key)
         
         func callHandlerInMainQueue() {
@@ -214,12 +214,12 @@ extension ImageCache {
         }
         
         if fromDisk {
-            ioQueue.async(execute: { () -> Void in
+            ioQueue.async{
                 do {
                     try self.fileManager.removeItem(atPath: self.cachePathForKey(key))
                 } catch _ {}
                 callHandlerInMainQueue()
-            })
+            }
         } else {
             callHandlerInMainQueue()
         }
@@ -238,7 +238,7 @@ extension ImageCache {
     
     - returns: The retrieving task.
     */
-    @discardableResult public func retrieveImageForKey(_ key: String, options: KingfisherOptionsInfo?, completionHandler: ((Image?, CacheType) -> ())?) -> RetrieveImageDiskTask? {
+    @discardableResult public func retrieveImage(forKey key: String, options: KingfisherOptionsInfo?, completionHandler: ((Image?, CacheType) -> ())?) -> RetrieveImageDiskTask? {
         // No completion handler. Not start working and early return.
         guard let completionHandler = completionHandler else {
             return nil
@@ -247,7 +247,7 @@ extension ImageCache {
         var block: RetrieveImageDiskTask?
         let options = options ?? KingfisherEmptyOptionsInfo
         
-        if let image = self.retrieveImageInMemoryCacheForKey(key) {
+        if let image = self.retrieveImageInMemoryCache(forKey: key) {
             options.callbackDispatchQueue.safeAsync {
                 completionHandler(image, .memory)
             }
@@ -295,7 +295,7 @@ extension ImageCache {
     
     - returns: The image object if it is cached, or `nil` if there is no such key in the cache.
     */
-    public func retrieveImageInMemoryCacheForKey(_ key: String) -> Image? {
+    public func retrieveImageInMemoryCache(forKey key: String) -> Image? {
         return memoryCache.object(forKey: key) as? Image
     }
     

+ 13 - 13
Sources/ImageDownloader.swift

@@ -258,11 +258,11 @@ extension ImageDownloader {
     - returns: A downloading task. You could call `cancel` on it to stop the downloading process.
     */
     @discardableResult
-    public func downloadImageWithURL(_ url: URL,
+    public func downloadImage(with url: URL,
                            progressBlock: ImageDownloaderProgressBlock?,
                        completionHandler: ImageDownloaderCompletionHandler?) -> RetrieveImageDownloadTask?
     {
-        return downloadImageWithURL(url, options: nil, progressBlock: progressBlock, completionHandler: completionHandler)
+        return downloadImage(with: url, options: nil, progressBlock: progressBlock, completionHandler: completionHandler)
     }
     
     /**
@@ -276,23 +276,23 @@ extension ImageDownloader {
     - returns: A downloading task. You could call `cancel` on it to stop the downloading process.
     */
     @discardableResult
-    public func downloadImageWithURL(_ url: URL,
+    public func downloadImage(with url: URL,
                                  options: KingfisherOptionsInfo?,
                            progressBlock: ImageDownloaderProgressBlock?,
                        completionHandler: ImageDownloaderCompletionHandler?) -> RetrieveImageDownloadTask?
     {
-        return downloadImageWithURL(url,
-            retrieveImageTask: nil,
-                      options: options,
-                progressBlock: progressBlock,
-            completionHandler: completionHandler)
+        return downloadImage(with: url,
+                retrieveImageTask: nil,
+                          options: options,
+                    progressBlock: progressBlock,
+                completionHandler: completionHandler)
     }
     
-    func downloadImageWithURL(_ url: URL,
-                       retrieveImageTask: RetrieveImageTask?,
-                                 options: KingfisherOptionsInfo?,
-                           progressBlock: ImageDownloaderProgressBlock?,
-                       completionHandler: ImageDownloaderCompletionHandler?) -> RetrieveImageDownloadTask?
+    func downloadImage(with url: URL,
+              retrieveImageTask: RetrieveImageTask?,
+                        options: KingfisherOptionsInfo?,
+                  progressBlock: ImageDownloaderProgressBlock?,
+              completionHandler: ImageDownloaderCompletionHandler?) -> RetrieveImageDownloadTask?
     {
         if let retrieveImageTask = retrieveImageTask, retrieveImageTask.cancelledBeforeDownloadStarting {
             return nil

+ 2 - 2
Sources/ImagePrefetcher.swift

@@ -193,8 +193,8 @@ public class ImagePrefetcher {
     func downloadAndCache(_ resource: Resource) {
 
         let task = RetrieveImageTask()
-        let downloadTask = manager.downloadAndCacheImageWithURL(
-            resource.downloadURL,
+        let downloadTask = manager.downloadAndCacheImage(
+            with: resource.downloadURL,
             forKey: resource.cacheKey,
             retrieveImageTask: task,
             progressBlock: nil,

+ 1 - 1
Sources/ImageView+Kingfisher.swift

@@ -114,7 +114,7 @@ extension ImageView {
             options.append(.preloadAllGIFData)
         }
 
-        let task = KingfisherManager.sharedManager.retrieveImageWithResource(resource, optionsInfo: options,
+        let task = KingfisherManager.shared.retrieveImageWithResource(resource, optionsInfo: options,
             progressBlock: { receivedSize, totalSize in
                 if let progressBlock = progressBlock {
                     progressBlock(receivedSize: receivedSize, totalSize: totalSize)

+ 22 - 25
Sources/KingfisherManager.swift

@@ -71,14 +71,14 @@ public class RetrieveImageTask {
 /// Error domain of Kingfisher
 public let KingfisherErrorDomain = "com.onevcat.Kingfisher.Error"
 
-private let instance = KingfisherManager()
-
 /// Main manager class of Kingfisher. It connects Kingfisher downloader and cache.
 /// You can use this class to retrieve an image via a specified URL from web or cache.
 public class KingfisherManager {
     
+    private static let instance = KingfisherManager()
+    
     /// Shared manager used by the extensions across Kingfisher.
-    public class var sharedManager: KingfisherManager {
+    public class var shared: KingfisherManager {
         return instance
     }
     
@@ -88,12 +88,7 @@ public class KingfisherManager {
     /// Downloader used by this manager
     public var downloader: ImageDownloader
     
-    /**
-    Default init method
-    
-    - returns: A Kingfisher manager object with default cache, default downloader, and default prefetcher.
-    */
-    public convenience init() {
+    convenience init() {
         self.init(downloader: .default, cache: .default)
     }
     
@@ -124,7 +119,8 @@ public class KingfisherManager {
         let task = RetrieveImageTask()
 
         if let optionsInfo = optionsInfo, optionsInfo.forceRefresh {
-            _ = downloadAndCacheImageWithURL(resource.downloadURL as URL,
+            _ = downloadAndCacheImage(
+                with: resource.downloadURL,
                 forKey: resource.cacheKey,
                 retrieveImageTask: task,
                 progressBlock: progressBlock,
@@ -132,7 +128,7 @@ public class KingfisherManager {
                 options: optionsInfo)
         } else {
             tryToRetrieveImageFromCacheForKey(resource.cacheKey,
-                withURL: resource.downloadURL as URL,
+                withURL: resource.downloadURL,
                 retrieveImageTask: task,
                 progressBlock: progressBlock,
                 completionHandler: completionHandler,
@@ -159,24 +155,24 @@ public class KingfisherManager {
     - returns: A `RetrieveImageTask` task object. You can use this object to cancel the task.
     */
     @discardableResult
-    public func retrieveImageWithURL(_ URL: URL,
+    public func retrieveImage(with url: URL,
                              optionsInfo: KingfisherOptionsInfo?,
                            progressBlock: DownloadProgressBlock?,
                        completionHandler: CompletionHandler?) -> RetrieveImageTask
     {
-        return retrieveImageWithResource(ImageResource(downloadURL: URL), optionsInfo: optionsInfo, progressBlock: progressBlock, completionHandler: completionHandler)
+        return retrieveImageWithResource(ImageResource(downloadURL: url), optionsInfo: optionsInfo, progressBlock: progressBlock, completionHandler: completionHandler)
     }
     
     @discardableResult
-    func downloadAndCacheImageWithURL(_ URL: Foundation.URL,
-                               forKey key: String,
-                        retrieveImageTask: RetrieveImageTask,
-                            progressBlock: DownloadProgressBlock?,
-                        completionHandler: CompletionHandler?,
-                                  options: KingfisherOptionsInfo?) -> RetrieveImageDownloadTask?
+    func downloadAndCacheImage(with url: URL,
+                             forKey key: String,
+                      retrieveImageTask: RetrieveImageTask,
+                          progressBlock: DownloadProgressBlock?,
+                      completionHandler: CompletionHandler?,
+                                options: KingfisherOptionsInfo?) -> RetrieveImageDownloadTask?
     {
         let downloader = options?.downloader ?? self.downloader
-        return downloader.downloadImageWithURL(URL, retrieveImageTask: retrieveImageTask, options: options,
+        return downloader.downloadImage(with: url, retrieveImageTask: retrieveImageTask, options: options,
             progressBlock: { receivedSize, totalSize in
                 progressBlock?(receivedSize: receivedSize, totalSize: totalSize)
             },
@@ -186,8 +182,8 @@ public class KingfisherManager {
                 if let error = error, error.code == KingfisherError.notModified.rawValue {
                     // Not modified. Try to find the image from cache.
                     // (The image should be in cache. It should be guaranteed by the framework users.)
-                    targetCache.retrieveImageForKey(key, options: options, completionHandler: { (cacheImage, cacheType) -> () in
-                        completionHandler?(image: cacheImage, error: nil, cacheType: cacheType, imageURL: URL)
+                    targetCache.retrieveImage(forKey: key, options: options, completionHandler: { (cacheImage, cacheType) -> () in
+                        completionHandler?(image: cacheImage, error: nil, cacheType: cacheType, imageURL: url)
                         
                     })
                     return
@@ -197,7 +193,7 @@ public class KingfisherManager {
                     targetCache.storeImage(image, originalData: originalData, forKey: key, toDisk: !(options?.cacheMemoryOnly ?? false), completionHandler: nil)
                 }
 
-                completionHandler?(image: image, error: error, cacheType: .none, imageURL: URL)
+                completionHandler?(image: image, error: error, cacheType: .none, imageURL: url)
 
             })
     }
@@ -216,7 +212,7 @@ public class KingfisherManager {
         }
         
         let targetCache = options?.targetCache ?? cache
-        let diskTask = targetCache.retrieveImageForKey(key, options: options,
+        let diskTask = targetCache.retrieveImage(forKey: key, options: options,
             completionHandler: { image, cacheType in
                 if image != nil {
                     diskTaskCompletionHandler(image: image, error: nil, cacheType:cacheType, imageURL: URL)
@@ -224,7 +220,8 @@ public class KingfisherManager {
                     let error = NSError(domain: KingfisherErrorDomain, code: KingfisherError.notCached.rawValue, userInfo: nil)
                     diskTaskCompletionHandler(image: nil, error: error, cacheType:.none, imageURL: URL)
                 } else {
-                    self.downloadAndCacheImageWithURL(URL,
+                    self.downloadAndCacheImage(
+                        with: URL,
                         forKey: key,
                         retrieveImageTask: retrieveImageTask,
                         progressBlock: progressBlock,

+ 3 - 3
Sources/NSButton+Kingfisher.swift

@@ -92,7 +92,7 @@ extension NSButton {
         }
         
         kf_setWebURL(resource.downloadURL)
-        let task = KingfisherManager.sharedManager.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
+        let task = KingfisherManager.shared.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
              progressBlock: { receivedSize, totalSize in
                 if let progressBlock = progressBlock {
                     progressBlock(receivedSize: receivedSize, totalSize: totalSize)
@@ -204,11 +204,11 @@ extension NSButton {
         
         guard let resource = resource else {
             completionHandler?(image: nil, error: nil, cacheType: .none, imageURL: nil)
-            return RetrieveImageTask.emptyTask
+            return .emptyTask
         }
         
         kf_setAlternateWebURL(resource.downloadURL)
-        let task = KingfisherManager.sharedManager.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
+        let task = KingfisherManager.shared.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
              progressBlock: { receivedSize, totalSize in
                 if let progressBlock = progressBlock {
                     progressBlock(receivedSize: receivedSize, totalSize: totalSize)

+ 2 - 2
Sources/UIButton+Kingfisher.swift

@@ -94,7 +94,7 @@ extension UIButton {
         }
         
         kf_setWebURL(resource.downloadURL as URL, forState: state)
-        let task = KingfisherManager.sharedManager.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
+        let task = KingfisherManager.shared.retrieveImageWithResource(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.sharedManager.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
+        let task = KingfisherManager.shared.retrieveImageWithResource(resource, optionsInfo: optionsInfo,
             progressBlock: { receivedSize, totalSize in
                 if let progressBlock = progressBlock {
                     progressBlock(receivedSize: receivedSize, totalSize: totalSize)

+ 9 - 9
Tests/KingfisherTests/ImageCacheTests.swift

@@ -96,7 +96,7 @@ class ImageCacheTests: XCTestCase {
         
         cache.storeImage(testImage, originalData: testImageData, forKey: testKeys[0], toDisk: true) { () -> () in
             self.cache.clearMemoryCache()
-            self.cache.retrieveImageForKey(testKeys[0], options: nil, completionHandler: { (image, type) -> () in
+            self.cache.retrieveImage(forKey: testKeys[0], options: nil, completionHandler: { (image, type) -> () in
                 XCTAssert(image != nil && type == .disk, "Should be cached in disk. But \(type)")
 
                 expectation.fulfill()
@@ -110,7 +110,7 @@ class ImageCacheTests: XCTestCase {
         let expectation = self.expectation(description: "wait for retrieving image")
         
         cache.clearDiskCache {
-            self.cache.retrieveImageForKey(testKeys[0], options: nil, completionHandler: { (image, type) -> () in
+            self.cache.retrieveImage(forKey: testKeys[0], options: nil, completionHandler: { (image, type) -> () in
                 XCTAssert(image == nil, "Should not be cached in memory yet")
                 expectation.fulfill()
             })
@@ -124,7 +124,7 @@ class ImageCacheTests: XCTestCase {
         let expectation = self.expectation(description: "wait for retrieving image")
         
         cache.storeImage(testImage, forKey: testKeys[0], toDisk: false) { () -> () in
-            self.cache.retrieveImageForKey(testKeys[0], options: nil, completionHandler: { (image, type) -> () in
+            self.cache.retrieveImage(forKey: testKeys[0], options: nil, completionHandler: { (image, type) -> () in
                 XCTAssert(image != nil && type == .memory, "Should be cached in memory.")
                 expectation.fulfill()
             })
@@ -162,21 +162,21 @@ class ImageCacheTests: XCTestCase {
         let exists = cache.cachedImageExists(for: URL)
         XCTAssertFalse(exists)
         
-        cache.retrieveImageForKey(URLString, options: nil, completionHandler: { (image, type) -> () in
+        cache.retrieveImage(forKey: URLString, options: nil, completionHandler: { (image, type) -> () in
             XCTAssertNil(image, "Should not be cached yet")
             
-            XCTAssertEqual(type, CacheType.none)
+            XCTAssertEqual(type, .none)
 
             self.cache.storeImage(testImage, forKey: URLString, toDisk: true) { () -> () in
-                self.cache.retrieveImageForKey(URLString, options: nil, completionHandler: { (image, type) -> () in
+                self.cache.retrieveImage(forKey: URLString, options: nil, completionHandler: { (image, type) -> () in
                     XCTAssertNotNil(image, "Should be cached (memory or disk)")
-                    XCTAssertEqual(type, CacheType.memory)
+                    XCTAssertEqual(type, .memory)
 
                     let exists = self.cache.cachedImageExists(for: URL)
                     XCTAssertTrue(exists, "Image should exist in the cache (memory or disk)")
 
                     self.cache.clearMemoryCache()
-                    self.cache.retrieveImageForKey(URLString, options: nil, completionHandler: { (image, type) -> () in
+                    self.cache.retrieveImage(forKey: URLString, options: nil, completionHandler: { (image, type) -> () in
                         XCTAssertNotNil(image, "Should be cached (disk)")
                         XCTAssertEqual(type, CacheType.disk)
                         
@@ -207,7 +207,7 @@ class ImageCacheTests: XCTestCase {
 
         var foundImage: Image?
 
-        cache.retrieveImageForKey(testKeys[0], options: [.backgroundDecode]) { (image, type) -> () in
+        cache.retrieveImage(forKey: testKeys[0], options: [.backgroundDecode]) { (image, type) -> () in
             foundImage = image
         }
 

+ 17 - 17
Tests/KingfisherTests/ImageDownloaderTests.swift

@@ -61,8 +61,8 @@ class ImageDownloaderTests: XCTestCase {
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
 
-        let URL = Foundation.URL(string: URLString)!
-        downloader.downloadImageWithURL(URL, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        let url = URL(string: URLString)!
+        downloader.downloadImage(with: url, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
             return
         }) { (image, error, imageURL, data) -> () in
             expectation.fulfill()
@@ -78,10 +78,10 @@ class ImageDownloaderTests: XCTestCase {
         let group = DispatchGroup()
         
         for URLString in testKeys {
-            if let URL = URL(string: URLString) {
+            if let url = URL(string: URLString) {
                 group.enter()
                 _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
-                downloader.downloadImageWithURL(URL, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
+                downloader.downloadImage(with: url, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
                     
                 }, completionHandler: { (image, error, imageURL, data) -> () in
                     XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL).")
@@ -106,7 +106,7 @@ class ImageDownloaderTests: XCTestCase {
 
         for _ in 0...5 {
             group.enter()
-            downloader.downloadImageWithURL(URL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
+            downloader.downloadImage(with: URL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
                 
                 }) { (image, error, imageURL, data) -> () in
                     XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL).")
@@ -134,7 +134,7 @@ class ImageDownloaderTests: XCTestCase {
         }
         
         let someURL = URL(string: "some_strange_url")!
-        downloader.downloadImageWithURL(someURL, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        downloader.downloadImage(with: someURL, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
         }) { (image, error, imageURL, data) -> () in
             XCTAssert(image != nil, "Download should be able to finished for URL: \(imageURL).")
@@ -150,7 +150,7 @@ class ImageDownloaderTests: XCTestCase {
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(304)
         
-        downloader.downloadImageWithURL(URL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        downloader.downloadImage(with: URL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
         }) { (image, error, imageURL, data) -> () in
             XCTAssertNotNil(error, "There should be an error since server returning 304 and no image downloaded.")
@@ -166,7 +166,7 @@ class ImageDownloaderTests: XCTestCase {
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(404)?.withBody(testImageData)
         
-        downloader.downloadImageWithURL(URL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
+        downloader.downloadImage(with: URL(string: URLString)!, options: nil, progressBlock: { (receivedSize, totalSize) -> () in
             
         }) { (image, error, imageURL, data) -> () in
             XCTAssertNotNil(error, "There should be an error since server returning 404")
@@ -184,11 +184,11 @@ class ImageDownloaderTests: XCTestCase {
         
         let downloader = ImageDownloader(name: "ssl.test")
         
-        let URL = Foundation.URL(string: "https://testssl-expire.disig.sk/Expired.png")!
+        let url = URL(string: "https://testssl-expire.disig.sk/Expired.png")!
         
         let expectation = self.expectation(description: "wait for download from an invalid ssl site.")
         
-        downloader.downloadImageWithURL(URL, progressBlock: nil, completionHandler: { (image, error, imageURL, data) -> () in
+        downloader.downloadImage(with: url, progressBlock: nil, completionHandler: { (image, error, imageURL, data) -> () in
             XCTAssertNotNil(error, "Error should not be nil")
             XCTAssert(error?.code == NSURLErrorServerCertificateUntrusted || error?.code == NSURLErrorSecureConnectionFailed, "Error should be NSURLErrorServerCertificateUntrusted, but \(error)")
             expectation.fulfill()
@@ -207,16 +207,16 @@ class ImageDownloaderTests: XCTestCase {
         
         let URLString = testKeys[0]
         stubRequest("GET", URLString).andFailWithError(NSError(domain: "stubError", code: -1, userInfo: nil))
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
-        downloader.downloadImageWithURL(URL, progressBlock: nil) { (image, error, imageURL, data) -> () in
+        downloader.downloadImage(with: url, progressBlock: nil) { (image, error, imageURL, data) -> () in
             XCTAssertNotNil(error, "Should return with an error")
             
             LSNocilla.sharedInstance().clearStubs()
             _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
             
             // Retry the download
-            self.downloader.downloadImageWithURL(URL, progressBlock: nil, completionHandler: { (image, error, imageURL, data) -> () in
+            self.downloader.downloadImage(with: url, progressBlock: nil, completionHandler: { (image, error, imageURL, data) -> () in
                 XCTAssertNil(error, "Download should be finished without error")
                 expectation.fulfill()
             })
@@ -233,7 +233,7 @@ class ImageDownloaderTests: XCTestCase {
         }
         
         let url = URL(string: "http://onevcat.com")
-        downloader.downloadImageWithURL(url!, progressBlock: { (receivedSize, totalSize) -> () in
+        downloader.downloadImage(with: url!, progressBlock: { (receivedSize, totalSize) -> () in
             XCTFail("The progress block should not be called.")
             }) { (image, error, imageURL, originalData) -> () in
                 XCTAssertNotNil(error, "An error should happen for empty URL")
@@ -246,7 +246,7 @@ class ImageDownloaderTests: XCTestCase {
     }
     
     func testDownloadTaskProperty() {
-        let task = downloader.downloadImageWithURL(URL(string: "1234")!, progressBlock: { (receivedSize, totalSize) -> () in
+        let task = downloader.downloadImage(with: URL(string: "1234")!, progressBlock: { (receivedSize, totalSize) -> () in
 
             }) { (image, error, imageURL, originalData) -> () in
         }
@@ -267,7 +267,7 @@ class ImageDownloaderTests: XCTestCase {
         var progressBlockIsCalled = false
         var completionBlockIsCalled = false
         
-        let downloadTask = downloader.downloadImageWithURL(URL, progressBlock: { (receivedSize, totalSize) -> () in
+        let downloadTask = downloader.downloadImage(with: URL, progressBlock: { (receivedSize, totalSize) -> () in
                 progressBlockIsCalled = true
             }) { (image, error, imageURL, originalData) -> () in
                 XCTAssertNotNil(error)
@@ -293,7 +293,7 @@ class ImageDownloaderTests: XCTestCase {
         downloader.requestModifier = { req in
             req.url = nil
         }
-        let downloadTask = downloader.downloadImageWithURL(URL(string: "url")!, progressBlock: nil, completionHandler: nil)
+        let downloadTask = downloader.downloadImage(with: URL(string: "url")!, progressBlock: nil, completionHandler: nil)
         XCTAssertNil(downloadTask)
         
         downloader.requestModifier = nil

+ 3 - 3
Tests/KingfisherTests/ImagePrefetcherTests.swift

@@ -76,7 +76,7 @@ class ImagePrefetcherTests: XCTestCase {
                 XCTAssertEqual(completedResources.count, urls.count, "All resources prefetching should be completed.")
                 XCTAssertEqual(progressCalledCount, urls.count, "Progress should be called the same time of download count.")
                 for url in urls {
-                    XCTAssertTrue(KingfisherManager.sharedManager.cache.isImageCachedForKey(url.absoluteString).cached)
+                    XCTAssertTrue(KingfisherManager.shared.cache.isImageCachedForKey(url.absoluteString).cached)
                 }
         }
         
@@ -123,7 +123,7 @@ class ImagePrefetcherTests: XCTestCase {
 
     func testPrefetcherCouldSkipCachedImages() {
         let expectation = self.expectation(description: "wait for prefetching images")
-        KingfisherManager.sharedManager.cache.storeImage(Image(), forKey: testKeys[0])
+        KingfisherManager.shared.cache.storeImage(Image(), forKey: testKeys[0])
         
         var urls = [URL]()
         for URLString in testKeys {
@@ -151,7 +151,7 @@ class ImagePrefetcherTests: XCTestCase {
         let expectation = self.expectation(description: "wait for prefetching images")
         
         // Store an image in cache.
-        KingfisherManager.sharedManager.cache.storeImage(Image(), forKey: testKeys[0])
+        KingfisherManager.shared.cache.storeImage(Image(), forKey: testKeys[0])
         
         var urls = [URL]()
         for URLString in testKeys {

+ 3 - 3
Tests/KingfisherTests/ImageViewExtensionTests.swift

@@ -45,7 +45,7 @@ class ImageViewExtensionTests: XCTestCase {
         super.setUp()
         // Put setup code here. This method is called before the invocation of each test method in the class.
         imageView = ImageView()
-        KingfisherManager.sharedManager.downloader = ImageDownloader(name: "testDownloader")
+        KingfisherManager.shared.downloader = ImageDownloader(name: "testDownloader")
         cleanDefaultCache()
     }
     
@@ -360,7 +360,7 @@ class ImageViewExtensionTests: XCTestCase {
             
             XCTAssertTrue(cache1.isImageCachedForKey(URLString).cached, "This image should be cached in cache1.")
             XCTAssertFalse(cache2.isImageCachedForKey(URLString).cached, "This image should not be cached in cache2.")
-            XCTAssertFalse(KingfisherManager.sharedManager.cache.isImageCachedForKey(URLString).cached, "This image should not be cached in default cache.")
+            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
                 
@@ -368,7 +368,7 @@ class ImageViewExtensionTests: XCTestCase {
                 
                 XCTAssertTrue(cache1.isImageCachedForKey(URLString).cached, "This image should be cached in cache1.")
                 XCTAssertTrue(cache2.isImageCachedForKey(URLString).cached, "This image should be cached in cache2.")
-                XCTAssertFalse(KingfisherManager.sharedManager.cache.isImageCachedForKey(URLString).cached, "This image should not be cached in default cache.")
+                XCTAssertFalse(KingfisherManager.shared.cache.isImageCachedForKey(URLString).cached, "This image should not be cached in default cache.")
                 
                 clearCaches([cache1, cache2])
                 

+ 20 - 20
Tests/KingfisherTests/KingfisherManagerTests.swift

@@ -60,26 +60,26 @@ class KingfisherManagerTests: XCTestCase {
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
         
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
 
-        manager.retrieveImageWithURL(URL, optionsInfo: nil, progressBlock: nil) {
+        manager.retrieveImage(with: url, optionsInfo: nil, progressBlock: nil) {
             image, error, cacheType, imageURL in
             XCTAssertNotNil(image)
-            XCTAssertEqual(cacheType, CacheType.none)
+            XCTAssertEqual(cacheType, .none)
             
-            self.manager.retrieveImageWithURL(URL, optionsInfo: nil, progressBlock: nil) {
+            self.manager.retrieveImage(with: url, optionsInfo: nil, progressBlock: nil) {
                 image, error, cacheType, imageURL in
                 XCTAssertNotNil(image)
-                XCTAssertEqual(cacheType, CacheType.memory)
+                XCTAssertEqual(cacheType, .memory)
                 
                 self.manager.cache.clearMemoryCache()
-                self.manager.retrieveImageWithURL(URL, optionsInfo: nil, progressBlock: nil) {
+                self.manager.retrieveImage(with: url, optionsInfo: nil, progressBlock: nil) {
                     image, error, cacheType, imageURL in
                     XCTAssertNotNil(image)
-                    XCTAssertEqual(cacheType, CacheType.disk)
+                    XCTAssertEqual(cacheType, .disk)
                     
                     cleanDefaultCache()
-                    self.manager.retrieveImageWithURL(URL, optionsInfo: [.forceRefresh], progressBlock: nil) {
+                    self.manager.retrieveImage(with: url, optionsInfo: [.forceRefresh], progressBlock: nil) {
                         image, error, cacheType, imageURL in
                         XCTAssertNotNil(image)
                         XCTAssertEqual(cacheType, CacheType.none)
@@ -98,9 +98,9 @@ class KingfisherManagerTests: XCTestCase {
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
         
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
-        manager.retrieveImageWithURL(URL, optionsInfo: nil, progressBlock: nil) {
+        manager.retrieveImage(with: url, optionsInfo: nil, progressBlock: nil) {
             image, error, cacheType, imageURL in
             XCTAssertNotNil(image)
             XCTAssertEqual(cacheType, CacheType.none)
@@ -113,7 +113,7 @@ class KingfisherManagerTests: XCTestCase {
             
             var progressCalled = false
             
-            self.manager.retrieveImageWithURL(URL, optionsInfo: [.forceRefresh], progressBlock: {
+            self.manager.retrieveImage(with: url, optionsInfo: [.forceRefresh], progressBlock: {
                 _, _ in
                 progressCalled = true
             }) {
@@ -136,9 +136,9 @@ class KingfisherManagerTests: XCTestCase {
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
         
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
-        manager.retrieveImageWithURL(URL, optionsInfo: nil, progressBlock: { _, _ in
+        manager.retrieveImage(with: url, optionsInfo: nil, progressBlock: { _, _ in
             XCTAssertTrue(Thread.isMainThread)
             progressExpectation.fulfill()
             }, completionHandler: { _, error, _, _ in
@@ -157,7 +157,7 @@ class KingfisherManagerTests: XCTestCase {
 
         let url = URL(string: URLString)!
 
-        manager.retrieveImageWithURL(url, optionsInfo: [.onlyFromCache], progressBlock: nil, completionHandler: { image, error, _, _ in
+        manager.retrieveImage(with: url, optionsInfo: [.onlyFromCache], progressBlock: nil, completionHandler: { image, error, _, _ in
                 XCTAssertNil(image)
                 XCTAssertNotNil(error)
                 XCTAssertEqual(error!.code, KingfisherError.notCached.rawValue)
@@ -171,9 +171,9 @@ class KingfisherManagerTests: XCTestCase {
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString)?.andReturn(404)
         
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
-        manager.retrieveImageWithURL(URL, optionsInfo: nil, progressBlock: { _, _ in
+        manager.retrieveImage(with: url, optionsInfo: nil, progressBlock: { _, _ in
             //won't be called
             }, completionHandler: { _, error, _, _ in
                 XCTAssertNotNil(error)
@@ -189,10 +189,10 @@ class KingfisherManagerTests: XCTestCase {
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString).andReturn(200)?.withBody(testImageData)
         
-        let URL = Foundation.URL(string: URLString)!
+        let url = Foundation.URL(string: URLString)!
         
         let customQueue = DispatchQueue(label: "com.kingfisher.testQueue")
-        manager.retrieveImageWithURL(URL, optionsInfo: [.callbackDispatchQueue(customQueue)], progressBlock: { _, _ in
+        manager.retrieveImage(with: url, optionsInfo: [.callbackDispatchQueue(customQueue)], progressBlock: { _, _ in
             XCTAssertTrue(Thread.isMainThread)
             progressExpectation.fulfill()
             }, completionHandler: { _, error, _, _ in
@@ -212,10 +212,10 @@ class KingfisherManagerTests: XCTestCase {
         let URLString = testKeys[0]
         _ = stubRequest("GET", URLString)?.andReturn(404)
         
-        let URL = Foundation.URL(string: URLString)!
+        let url = URL(string: URLString)!
         
         let customQueue = DispatchQueue(label: "com.kingfisher.testQueue")
-        manager.retrieveImageWithURL(URL, optionsInfo: [.callbackDispatchQueue(customQueue)], progressBlock: { _, _ in
+        manager.retrieveImage(with: url, optionsInfo: [.callbackDispatchQueue(customQueue)], progressBlock: { _, _ in
             //won't be called
             }, completionHandler: { _, error, _, _ in
                 XCTAssertNotNil(error)

+ 1 - 1
Tests/KingfisherTests/KingfisherTestHelper.swift

@@ -45,7 +45,7 @@ func == (left: Image, right: Image) -> Bool {
 }
 
 func cleanDefaultCache() {
-    clearCaches([KingfisherManager.sharedManager.cache])
+    clearCaches([KingfisherManager.shared.cache])
 }
 
 func clearCaches(_ caches: [ImageCache]) {

+ 1 - 1
Tests/KingfisherTests/NSButtonExtensionTests.swift

@@ -46,7 +46,7 @@ class NSButtonExtensionTests: XCTestCase {
         super.setUp()
         // Put setup code here. This method is called before the invocation of each test method in the class.
         button = NSButton()
-        KingfisherManager.sharedManager.downloader = ImageDownloader(name: "testDownloader")
+        KingfisherManager.shared.downloader = ImageDownloader(name: "testDownloader")
         cleanDefaultCache()
     }
 

+ 1 - 1
Tests/KingfisherTests/UIButtonExtensionTests.swift

@@ -46,7 +46,7 @@ class UIButtonExtensionTests: XCTestCase {
         super.setUp()
         // Put setup code here. This method is called before the invocation of each test method in the class.
         button = UIButton()
-        KingfisherManager.sharedManager.downloader = ImageDownloader(name: "testDownloader")
+        KingfisherManager.shared.downloader = ImageDownloader(name: "testDownloader")
         cleanDefaultCache()
     }