extension Encodable {
func toData() -> Data? {
let encoder = JSONEncoder()
return try?encoder.encode(self)
}
}
extension Decodable {
static func toModel(from data: Data) -> Self? {
let decoder = JSONDecoder()
return try? decoder.decode(Self.self, from: data)
}
}
网友评论