File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
RESTAPI/ValidResponseData Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 7
7
import Foundation
8
8
import SwiftyJSON
9
9
10
+ public struct JSONDecoderStore {
11
+
12
+ private static var storage : [ String : JSONDecoder ] = [ : ]
13
+
14
+ public static let defaultDecoder = JSONDecoder ( )
15
+
16
+ public static subscript( _ type: JSONCodable . Type ) -> JSONDecoder {
17
+ get { storage [ String ( describing: type) ] ?? defaultDecoder }
18
+ set { storage [ String ( describing: type) ] = newValue}
19
+ }
20
+ }
21
+
10
22
public protocol JSONCodable : ValidResponseData { }
11
23
12
24
public extension JSONCodable where Self: Decodable {
13
25
14
26
static func createInstance( from data: Data ) throws -> Self {
15
- let decoder = JSONDecoder ( )
16
- return try decoder. decode ( Self . self, from: data)
27
+ return try JSONDecoderStore [ Self] . decode ( Self . self, from: data)
17
28
}
18
29
}
19
30
You can’t perform that action at this time.
0 commit comments