@@ -121,42 +121,30 @@ open class ImageDrawer {
121121 // MARK: Cache
122122
123123 private static let lock : NSLock = NSLock ( )
124- private static var cachedImages = [ String: UIImage] ( )
125- private var cacheKey : String {
126- var attributes = [ String: String] ( )
127- attributes [ " colors " ] = String ( self . colors. description. hashValue)
128- attributes [ " colorLocations " ] = String ( self . colorLocations. description. hashValue)
129- attributes [ " colorStartPoint " ] = String ( String ( describing: self . colorStartPoint) . hashValue)
130- attributes [ " colorEndPoint " ] = String ( String ( describing: self . colorEndPoint) . hashValue)
131-
132- attributes [ " borderColors " ] = String ( self . borderColors. description. hashValue)
133- attributes [ " borderColorLocations " ] = String ( self . borderColorLocations. description. hashValue)
134- attributes [ " borderColorStartPoint " ] = String ( String ( describing: self . borderColorStartPoint) . hashValue)
135- attributes [ " borderColorEndPoint " ] = String ( String ( describing: self . borderColorEndPoint) . hashValue)
136- attributes [ " borderWidth " ] = String ( self . borderWidth. hashValue)
137- attributes [ " borderAlignment " ] = String ( self . borderAlignment. hashValue)
138-
139- attributes [ " cornerRadiusTopLeft " ] = String ( self . cornerRadiusTopLeft. hashValue)
140- attributes [ " cornerRadiusTopRight " ] = String ( self . cornerRadiusTopRight. hashValue)
141- attributes [ " cornerRadiusBottomLeft " ] = String ( self . cornerRadiusBottomLeft. hashValue)
142- attributes [ " cornerRadiusBottomRight " ] = String ( self . cornerRadiusBottomRight. hashValue)
143-
144- switch self . size {
145- case . fixed( let size) :
146- attributes [ " size " ] = " Fixed( \( size. width) , \( size. height) ) "
147- case . resizable:
148- attributes [ " size " ] = " Resizable "
149- }
150-
151- var serializedAttributes = [ String] ( )
152- for key in attributes. keys. sorted ( ) {
153- if let value = attributes [ key] {
154- serializedAttributes. append ( " \( key) : \( value) " )
155- }
156- }
157-
158- let cacheKey = serializedAttributes. joined ( separator: " | " )
159- return cacheKey
124+ private static var cachedImages = [ AnyHashable: UIImage] ( )
125+ private var cacheKey : AnyHashable {
126+ var hasher = Hasher ( )
127+
128+ hasher. combine ( self . colors)
129+ hasher. combine ( self . colorLocations)
130+ hasher. combine ( String ( describing: self . colorStartPoint) )
131+ hasher. combine ( String ( describing: self . colorEndPoint) )
132+
133+ hasher. combine ( self . borderColors)
134+ hasher. combine ( self . borderColorLocations)
135+ hasher. combine ( String ( describing: self . borderColorStartPoint) )
136+ hasher. combine ( String ( describing: self . borderColorEndPoint) )
137+ hasher. combine ( self . borderWidth)
138+ hasher. combine ( self . borderAlignment)
139+
140+ hasher. combine ( self . cornerRadiusTopLeft)
141+ hasher. combine ( self . cornerRadiusTopRight)
142+ hasher. combine ( self . cornerRadiusBottomLeft)
143+ hasher. combine ( self . cornerRadiusBottomRight)
144+
145+ hasher. combine ( String ( describing: self . size) )
146+
147+ return hasher. finalize ( )
160148 }
161149
162150
0 commit comments