Kaynağa Gözat

Reverse nonmutating set; create parallel KingfisherCompatible for value types

Garth Snyder 7 yıl önce
ebeveyn
işleme
25c163cb2d

+ 15 - 4
Sources/General/Kingfisher.swift

@@ -56,16 +56,27 @@ public struct KingfisherWrapper<Base> {
     }
 }
 
-/// Represents a type which is compatible with Kingfisher. You can use `kf` property to get a
+/// Represents an object type that is compatible with Kingfisher. You can use `kf` property to get a
 /// value in the namespace of Kingfisher.
-public protocol KingfisherCompatible { }
+public protocol KingfisherCompatible: AnyObject { }
+
+/// Represents a value type that is compatible with Kingfisher. You can use `kf` property to get a
+/// value in the namespace of Kingfisher.
+public protocol KingfisherCompatibleValue {}
 
 extension KingfisherCompatible {
-    
     /// Gets a namespace holder for Kingfisher compatible types.
     public var kf: KingfisherWrapper<Self> {
         get { return KingfisherWrapper(self) }
-        nonmutating set { }
+        set { }
+    }
+}
+
+extension KingfisherCompatibleValue {
+    /// Gets a namespace holder for Kingfisher compatible types.
+    public var kf: KingfisherWrapper<Self> {
+        get { return KingfisherWrapper(self) }
+        set { }
     }
 }
 

+ 1 - 1
Sources/Image/ImageFormat.swift

@@ -51,7 +51,7 @@ public enum ImageFormat {
 }
 
 
-extension Data: KingfisherCompatible {}
+extension Data: KingfisherCompatibleValue {}
 
 // MARK: - Misc Helpers
 extension KingfisherWrapper where Base == Data {

+ 1 - 1
Sources/Utility/SizeExtensions.swift

@@ -26,7 +26,7 @@
 
 import CoreGraphics
 
-extension CGSize: KingfisherCompatible {}
+extension CGSize: KingfisherCompatibleValue {}
 extension KingfisherWrapper where Base == CGSize {
     
     /// Returns a size by resizing the `base` size to a target size under a given content mode.

+ 1 - 1
Sources/Utility/String+MD5.swift

@@ -27,7 +27,7 @@
 import Foundation
 import CommonCrypto
 
-extension String: KingfisherCompatible { }
+extension String: KingfisherCompatibleValue { }
 extension KingfisherWrapper where Base == String {
     var md5: String {
         guard let data = base.data(using: .utf8) else {