Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,6 @@ public extension KeyedEncodingContainerProtocol {
try self.encodeMap(pairs)
}
}

mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try self.encode(stringValue, forKey: key)
}

mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
if let value {
try self.encode(value, forKey: key)
}
}
}

public extension KeyedDecodingContainerProtocol {
Expand Down Expand Up @@ -213,34 +201,6 @@ public extension KeyedDecodingContainerProtocol {

return map
}

func decode(_ type: Decimal.Type, forKey key: Self.Key) throws -> Decimal {
let stringValue = try decode(String.self, forKey: key)
guard let decimalValue = Decimal(string: stringValue) else {
let context = DecodingError.Context(
codingPath: [key],
debugDescription: "The key \(key) couldn't be converted to a Decimal value"
)
throw DecodingError.typeMismatch(type, context)
}

return decimalValue
}

func decodeIfPresent(_ type: Decimal.Type, forKey key: Self.Key) throws -> Decimal? {
guard let stringValue = try decodeIfPresent(String.self, forKey: key) else {
return nil
}
guard let decimalValue = Decimal(string: stringValue) else {
let context = DecodingError.Context(
codingPath: [key],
debugDescription: "The key \(key) couldn't be converted to a Decimal value"
)
throw DecodingError.typeMismatch(type, context)
}

return decimalValue
}
}

extension HTTPURLResponse {
Expand Down