Explorar o código

Fix code styles to pass lint

onevcat %!s(int64=10) %!d(string=hai) anos
pai
achega
7023fd60de

+ 1 - 1
Kingfisher/ImageCache.swift

@@ -265,7 +265,7 @@ extension ImageCache {
     
     - returns: The retrieving task.
     */
-    public func retrieveImageForKey(key: String, options:KingfisherManager.Options, completionHandler: ((UIImage?, CacheType!) -> ())?) -> RetrieveImageDiskTask? {
+    public func retrieveImageForKey(key: String, options: KingfisherManager.Options, completionHandler: ((UIImage?, CacheType!) -> ())?) -> RetrieveImageDiskTask? {
         // No completion handler. Not start working and early return.
         guard let completionHandler = completionHandler else {
             return nil

+ 3 - 3
Kingfisher/KingfisherManager.swift

@@ -248,7 +248,7 @@ public class KingfisherManager {
             return (options, targetCache, targetDownloader)
         }
         
-        if let optionsItem = optionsInfo.kf_findFirstMatch(.Options(.None)), case .Options(let optionsInOptionsInfo) = optionsItem {
+        if let optionsItem = optionsInfo.kf_firstMatchIgnoringAssociatedValue(.Options(.None)), case .Options(let optionsInOptionsInfo) = optionsItem {
             
             let queue = optionsInOptionsInfo.contains(KingfisherOptions.BackgroundCallback) ? dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) : KingfisherManager.DefaultOptions.queue
             let scale = optionsInOptionsInfo.contains(KingfisherOptions.ScreenScale) ? UIScreen.mainScreen().scale : KingfisherManager.DefaultOptions.scale
@@ -260,11 +260,11 @@ public class KingfisherManager {
                 queue: queue, scale: scale)
         }
         
-        if let optionsItem = optionsInfo.kf_findFirstMatch(.TargetCache(self.cache)), case .TargetCache(let cache) = optionsItem {
+        if let optionsItem = optionsInfo.kf_firstMatchIgnoringAssociatedValue(.TargetCache(self.cache)), case .TargetCache(let cache) = optionsItem {
             targetCache = cache
         }
         
-        if let optionsItem = optionsInfo.kf_findFirstMatch(.Downloader(self.downloader)), case .Downloader(let downloader) = optionsItem {
+        if let optionsItem = optionsInfo.kf_firstMatchIgnoringAssociatedValue(.Downloader(self.downloader)), case .Downloader(let downloader) = optionsItem {
             targetDownloader = downloader
         }
         

+ 7 - 5
Kingfisher/KingfisherOptionsInfo.swift

@@ -51,8 +51,9 @@ infix operator <== {
     precedence 160
 }
 
-func <== (a: KingfisherOptionsInfoItem, b: KingfisherOptionsInfoItem) -> Bool {
-    switch (a, b) {
+// This operator returns true if two `KingfisherOptionsInfoItem` enum is the same, without considering the associated values.
+func <== (lhs: KingfisherOptionsInfoItem, rhs: KingfisherOptionsInfoItem) -> Bool {
+    switch (lhs, rhs) {
     case (.Options(_), .Options(_)): return true
     case (.TargetCache(_), .TargetCache(_)): return true
     case (.Downloader(_), .Downloader(_)): return true
@@ -62,11 +63,12 @@ func <== (a: KingfisherOptionsInfoItem, b: KingfisherOptionsInfoItem) -> Bool {
 }
 
 extension CollectionType where Generator.Element == KingfisherOptionsInfoItem {
-    func kf_findFirstMatch(target: Generator.Element) -> Generator.Element? {
+    
+    func kf_firstMatchIgnoringAssociatedValue(target: Generator.Element) -> Generator.Element? {
         
         let index = indexOf {
-            e in
-            return e <== target
+            item in
+            return item <== target
         }
         
         return (index != nil) ? self[index!] : nil

+ 19 - 19
Kingfisher/String+MD5.swift

@@ -94,8 +94,8 @@ class HashBase {
         tmpMessage.appendBytes([0x80]) // append one bit (UInt8 with one bit) to message
         
         // append "0" bit until message length in bits ≡ 448 (mod 512)
-        var msgLength = tmpMessage.length;
-        var counter = 0;
+        var msgLength = tmpMessage.length
+        var counter = 0
         while msgLength % len != (len - 8) {
             counter++
             msgLength++
@@ -110,20 +110,20 @@ class HashBase {
     }
 }
 
-func rotateLeft(v:UInt32, n:UInt32) -> UInt32 {
-    return ((v << n) & 0xFFFFFFFF) | (v >> (32 - n))
+func rotateLeft(value: UInt32, bits: UInt32) -> UInt32 {
+    return ((value << bits) & 0xFFFFFFFF) | (value >> (32 - bits))
 }
 
 class MD5 : HashBase {
     
     /** specifies the per-round shift amounts */
-    private let s: [UInt32] = [7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,
+    private let shifts: [UInt32] = [7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,
         5,  9, 14, 20,  5,  9, 14, 20,  5,  9, 14, 20,  5,  9, 14, 20,
         4, 11, 16, 23,  4, 11, 16, 23,  4, 11, 16, 23,  4, 11, 16, 23,
         6, 10, 15, 21,  6, 10, 15, 21,  6, 10, 15, 21,  6, 10, 15, 21]
     
     /** binary integer part of the sines of integers (Radians) */
-    private let k: [UInt32] = [0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
+    private let sines: [UInt32] = [0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
                                0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
                                0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
                                0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
@@ -140,18 +140,18 @@ class MD5 : HashBase {
                                0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
                                0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391]
     
-    private let h:[UInt32] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
+    private let hashs: [UInt32] = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476]
     
     func calculate() -> NSData {
         let tmpMessage = prepare()
         
         // hash values
-        var hh = h
+        var hh = hashs
         
         // Step 2. Append Length a 64-bit representation of lengthInBits
         let lengthInBits = (message.length * 8)
         let lengthBytes = lengthInBits.bytes(64 / 8)
-        tmpMessage.appendBytes(Array(lengthBytes.reverse()));
+        tmpMessage.appendBytes(Array(lengthBytes.reverse()))
         
         // Process the message in successive 512-bit chunks:
         let chunkSizeBytes = 512 / 8 // 64
@@ -160,20 +160,20 @@ class MD5 : HashBase {
             let chunk = tmpMessage.subdataWithRange(NSRange(location: i, length: min(chunkSizeBytes, leftMessageBytes)))
             
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15
-            var M:[UInt32] = [UInt32](count: 16, repeatedValue: 0)
+            var M: [UInt32] = [UInt32](count: 16, repeatedValue: 0)
             let range = NSRange(location:0, length: M.count * sizeof(UInt32))
             chunk.getBytes(UnsafeMutablePointer<Void>(M), range: range)
             
             // Initialize hash value for this chunk:
-            var A:UInt32 = hh[0]
-            var B:UInt32 = hh[1]
-            var C:UInt32 = hh[2]
-            var D:UInt32 = hh[3]
+            var A: UInt32 = hh[0]
+            var B: UInt32 = hh[1]
+            var C: UInt32 = hh[2]
+            var D: UInt32 = hh[3]
             
-            var dTemp:UInt32 = 0
+            var dTemp: UInt32 = 0
             
             // Main loop
-            for j in 0..<k.count {
+            for j in 0 ..< sines.count {
                 var g = 0
                 var F: UInt32 = 0
                 
@@ -200,7 +200,7 @@ class MD5 : HashBase {
                 dTemp = D
                 D = C
                 C = B
-                B = B &+ rotateLeft((A &+ F &+ k[j] &+ M[g]), n: s[j])
+                B = B &+ rotateLeft((A &+ F &+ sines[j] &+ M[g]), bits: shifts[j])
                 A = dTemp
             }
             
@@ -210,12 +210,12 @@ class MD5 : HashBase {
             hh[3] = hh[3] &+ D
         }
         
-        let buf: NSMutableData = NSMutableData();
+        let buf: NSMutableData = NSMutableData()
         hh.forEach({ (item) -> () in
             var i:UInt32 = item.littleEndian
             buf.appendBytes(&i, length: sizeofValue(i))
         })
         
-        return buf.copy() as! NSData;
+        return buf.copy() as! NSData
     }
 }

+ 1 - 1
Kingfisher/UIImage+Extension.swift

@@ -95,7 +95,7 @@ extension UIImage {
         let normalizedImage = UIGraphicsGetImageFromCurrentImageContext()
         UIGraphicsEndImageContext()
         
-        return normalizedImage;
+        return normalizedImage
     }
 }
 

+ 2 - 2
Kingfisher/UIImageView+Kingfisher.swift

@@ -201,7 +201,7 @@ public extension UIImageView {
                 dispatch_async_safely_main_queue {
                     if let sSelf = self where imageURL == sSelf.kf_webURL && image != nil {
                         
-                        if let transitionItem = optionsInfo?.kf_findFirstMatch(.Transition(.None)),
+                        if let transitionItem = optionsInfo?.kf_firstMatchIgnoringAssociatedValue(.Transition(.None)),
                             case .Transition(let transition) = transitionItem where cacheType == .None {
                             
                             UIView.transitionWithView(sSelf, duration: 0.0, options: [],
@@ -223,7 +223,7 @@ public extension UIImageView {
                             )
                         } else {
                             indicator?.stopAnimating()
-                            sSelf.image = image;
+                            sSelf.image = image
                             completionHandler?(image: image, error: error, cacheType: cacheType, imageURL: imageURL)
                         }
                     } else {