Skip to content

Commit

Permalink
Merge pull request #5 from Lickability/update-json-parsing-API
Browse files Browse the repository at this point in the history
Makes `JSONDecoder` Injectable
  • Loading branch information
bcapps authored May 31, 2022
2 parents 54ba83b + 4c28e1f commit 70ca4b6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Sources/Networking/NetworkRequestPerformer+JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ extension NetworkRequestPerformer {
/// - Parameters:
/// - request: The request to perform.
/// - requestBehaviors: The behaviors to apply to the given request.
/// - decoder: The JSON decoder to use when decoding the data.
/// - completion: A completion closure that is called when the request has been completed.
/// - Returns: The `URLSessionDataTask` used to send the request. The implementation must call `resume()` on the task before returning.
@discardableResult public func send<ResponseType: Decodable>(_ request: NetworkRequest, requestBehaviors: [RequestBehavior] = [], completion: ((Result<ResponseType, NetworkError>) -> Void)? = nil) -> URLSessionDataTask {
@discardableResult public func send<ResponseType: Decodable>(_ request: NetworkRequest, requestBehaviors: [RequestBehavior] = [], decoder: JSONDecoder = JSONDecoder(), completion: ((Result<ResponseType, NetworkError>) -> Void)? = nil) -> URLSessionDataTask {
send(request, requestBehaviors: requestBehaviors) { result in
switch result {
case let .success(response):

let decoder = JSONDecoder()
if let data = response.data {
do {
let decodedInstance = try decoder.decode(ResponseType.self, from: data)
Expand Down

0 comments on commit 70ca4b6

Please sign in to comment.