Browse Source

Merge pull request #196 from onevcat/tripleCC-master

Triple cc master
Wei Wang 10 years ago
parent
commit
b61b5b595d
2 changed files with 8 additions and 17 deletions
  1. 7 16
      Kingfisher/ImageCache.swift
  2. 1 1
      KingfisherTests/ImageCacheTests.swift

+ 7 - 16
Kingfisher/ImageCache.swift

@@ -452,16 +452,16 @@ extension ImageCache {
                 let targetSize = self.maxDiskCacheSize / 2
                     
                 // Sort files by last modify date. We want to clean from the oldest files.
-                let sortedFiles = cachedFiles.keysSortedByValue({ (resourceValue1, resourceValue2) -> Bool in
+                let sortedFiles = cachedFiles.keysSortedByValue {
+                    resourceValue1, resourceValue2 -> Bool in
                     
-                    if let date1 = resourceValue1[NSURLContentModificationDateKey] as? NSDate {
-                        if let date2 = resourceValue2[NSURLContentModificationDateKey] as? NSDate {
-                            return date1.compare(date2) == .OrderedAscending
-                        }
+                    if let date1 = resourceValue1[NSURLContentModificationDateKey] as? NSDate,
+                           date2 = resourceValue2[NSURLContentModificationDateKey] as? NSDate {
+                        return date1.compare(date2) == .OrderedAscending
                     }
                     // Not valid date information. This should not happen. Just in case.
                     return true
-                })
+                }
                 
                 for fileURL in sortedFiles {
                     
@@ -653,15 +653,6 @@ extension UIImage {
 
 extension Dictionary {
     func keysSortedByValue(isOrderedBefore: (Value, Value) -> Bool) -> [Key] {
-        var array = Array(self)
-        array.sortInPlace {
-            let (_, lv) = $0
-            let (_, rv) = $1
-            return isOrderedBefore(lv, rv)
-        }
-        return array.map {
-            let (k, _) = $0
-            return k
-        }
+        return Array(self).sort{ isOrderedBefore($0.1, $1.1) }.map{ $0.0 }
     }
 }

+ 1 - 1
KingfisherTests/ImageCacheTests.swift

@@ -99,7 +99,7 @@ class ImageCacheTests: XCTestCase {
         cache.storeImage(testImage, originalData: testImageData, forKey: testKeys[0], toDisk: true) { () -> () in
             self.cache.clearMemoryCache()
             self.cache.retrieveImageForKey(testKeys[0], options: KingfisherManager.OptionsNone, completionHandler: { (image, type) -> () in
-                XCTAssert(image != nil && type == .Disk, "Should be cached in disk.")
+                XCTAssert(image != nil && type == .Disk, "Should be cached in disk. But \(type)")
                 expectation.fulfill()
             })
         }