Improved the MockURLProtocol class in the Foundation library to support optional object in its Response struct.
This commit is contained in:
parent
ac1074324d
commit
f6a72e8465
@ -66,12 +66,12 @@ extension MockURLProtocol {
|
||||
|
||||
// MARK: Constants
|
||||
public let statusCode: Int
|
||||
public let object: any Encodable
|
||||
public let object: (any Encodable)?
|
||||
|
||||
// MARK: Initialisers
|
||||
public init(
|
||||
statusCode: Int,
|
||||
object: any Codable
|
||||
object: (any Codable)? = nil
|
||||
) {
|
||||
self.statusCode = statusCode
|
||||
self.object = object
|
||||
@ -80,7 +80,9 @@ extension MockURLProtocol {
|
||||
// MARK: Computed
|
||||
var data: Data? {
|
||||
get throws {
|
||||
try JSONEncoder().encode(object)
|
||||
guard let object else { return nil }
|
||||
|
||||
return try JSONEncoder.default.encode(object)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user