ClassA conforming to Cadable and has a bunch of properties. One of them is a property of an already existing very complex ClassB that does not conform to Codable. Can I manually decode a non Codable property of a Codable class?
struct ClassA: Codable {
let title: String?
let subtitle: String?
let property: ClassB?
enum CodingKeys: String, CodingKey {
case title
case subtitle
case property
}
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
title = try container.decode(String.self, forKey: .title)
subtitle = try container.decode(String.self, forKey: .subtitle)
let JSONString = ?
property = ClassB.initWith(JSONString: JSONString)
}
class ClassB: NSObject {
// Already existing very complex ClassB implemenatation...
}
I get error:
Type 'ClassA' does not conform to protocol 'Encodable'
init(fromDecoder:)(and similarly on the Encodable side if you need it). But you cannot make ClassA Codable at all if it has a ClassB property and ClassB isn't Codable. - matt