瀏覽代碼

Change back to collection based extension

onevcat 8 年之前
父節點
當前提交
400bac8705
共有 1 個文件被更改,包括 7 次插入8 次删除
  1. 7 8
      Sources/KingfisherOptionsInfo.swift

+ 7 - 8
Sources/KingfisherOptionsInfo.swift

@@ -152,19 +152,18 @@ func <== (lhs: KingfisherOptionsInfoItem, rhs: KingfisherOptionsInfoItem) -> Boo
     }
 }
 
-extension Array where Element == KingfisherOptionsInfoItem {
-    
-    func lastMatchIgnoringAssociatedValue(_ target: Element) -> Element? {
-        return reversed().index { $0 <== target }
-            .flatMap { self[self.count - $0 - 1] }
+
+extension Collection where Iterator.Element == KingfisherOptionsInfoItem {
+    func lastMatchIgnoringAssociatedValue(_ target: Iterator.Element) -> Iterator.Element? {
+        return reversed().first { $0 <== target }
     }
     
-    func removeAllMatchesIgnoringAssociatedValue(_ target: Element) -> [Element] {
+    func removeAllMatchesIgnoringAssociatedValue(_ target: Iterator.Element) -> [Iterator.Element] {
         return filter { !($0 <== target) }
     }
 }
 
-public extension Array where Element == KingfisherOptionsInfoItem {
+public extension Collection where Iterator.Element == KingfisherOptionsInfoItem {
     /// The target `ImageCache` which is used.
     public var targetCache: ImageCache {
         if let item = lastMatchIgnoringAssociatedValue(.targetCache(.default)),
@@ -298,7 +297,7 @@ public extension Array where Element == KingfisherOptionsInfoItem {
 }
 
 // MARK: - Deprecated. Only for back compatibility.
-public extension Array where Element == KingfisherOptionsInfoItem {
+public extension Collection where Iterator.Element == KingfisherOptionsInfoItem {
 
     /// Whether the image data should be all loaded at once if it is a GIF.
     @available(*, deprecated, renamed: "preloadAllAnimationData")