mirror of
https://github.com/jphong1111/awesome-ios-developer.git
synced 2025-07-08 14:58:10 +07:00
Update JSONParameterEncoder.swift
This commit is contained in:
@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public struct JSONParameterEncoder: ParameterEncoder {
|
struct JSONParameterEncoder: ParameterEncoder {
|
||||||
public func encode(urlRequest: inout URLRequest, with parameters: Parameters) throws {
|
static func encode(urlRequest: inout URLRequest, with parameters: Parameters) throws {
|
||||||
do {
|
do {
|
||||||
let jsonAsData = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)
|
let jsonAsData = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)
|
||||||
urlRequest.httpBody = jsonAsData
|
urlRequest.httpBody = jsonAsData
|
||||||
@ -16,7 +16,7 @@ public struct JSONParameterEncoder: ParameterEncoder {
|
|||||||
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
throw NetworkError.encodingFailed
|
throw AppError.encodingFail
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user