Rocket.Chat.ReactNative/ios/RocketChat Watch App/Client/FailableDecodable.swift

14 lines
361 B
Swift
Raw Normal View History

2024-04-26 20:33:11 +00:00
struct FailableDecodable<Value: Codable & Hashable>: Codable, Hashable {
let value: Value?
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
value = try? container.decode(Value.self)
}
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(value)
}
}