Skip to content

Commit d570c2f

Browse files
committed
Reuse json decoder
1 parent f939eef commit d570c2f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

NetworkStack.playground/Contents.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ protocol ParserProtocol {
108108
}
109109

110110
struct Parser {
111-
111+
let jsonDecoder = JSONDecoder()
112+
112113
func json<T: Decodable>(data: Data, completition: @escaping ResultCallback<T>) {
113114
do {
114-
let result: T = try JSONDecoder().decode(T.self, from: data)
115+
let result: T = try jsonDecoder.decode(T.self, from: data)
115116
OperationQueue.main.addOperation { completition(.success(result)) }
116117

117118
} catch let parseError {

0 commit comments

Comments
 (0)