Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes JSONDecoder Injectable #5

Merged
merged 1 commit into from
May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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