Browse Source

Removed Implicit Unwrapping of CacheType that caused crashes if the image wasn cached

Giordano Scalzo 9 years ago
parent
commit
39091e88c7
2 changed files with 4 additions and 3 deletions
  1. 2 2
      Sources/ImageCache.swift
  2. 2 1
      Tests/KingfisherTests/ImageCacheTests.swift

+ 2 - 2
Sources/ImageCache.swift

@@ -243,7 +243,7 @@ extension ImageCache {
     
     - returns: The retrieving task.
     */
-    public func retrieveImageForKey(key: String, options: KingfisherOptionsInfo?, completionHandler: ((Image?, CacheType!) -> ())?) -> RetrieveImageDiskTask? {
+    public func retrieveImageForKey(key: String, options: KingfisherOptionsInfo?, completionHandler: ((Image?, CacheType) -> ())?) -> RetrieveImageDiskTask? {
         // No completion handler. Not start working and early return.
         guard let completionHandler = completionHandler else {
             return nil
@@ -281,7 +281,7 @@ extension ImageCache {
                 } else {
                     // No image found from either memory or disk
                     dispatch_async_safely_to_queue(options.callbackDispatchQueue, { () -> Void in
-                        completionHandler(nil, nil)
+                        completionHandler(nil, .None)
                         sSelf = nil
                     })
                 }

+ 2 - 1
Tests/KingfisherTests/ImageCacheTests.swift

@@ -164,7 +164,8 @@ class ImageCacheTests: XCTestCase {
         
         cache.retrieveImageForKey(URLString, options: nil, completionHandler: { (image, type) -> () in
             XCTAssertNil(image, "Should not be cached yet")
-            XCTAssertEqual(type, nil)
+            
+            XCTAssertEqual(type, CacheType.None)
 
             self.cache.storeImage(testImage, forKey: URLString, toDisk: true) { () -> () in
                 self.cache.retrieveImageForKey(URLString, options: nil, completionHandler: { (image, type) -> () in