I have this struct
struct Photo: Codable {
var image: UIImage
let caption: String?
let location: CLLocationCoordinate2D?
}
private enum CodingKeys: String, CodingKey {
case image = "image"
case caption = "caption"
case location = "location"
}
I get this 2 errors:
Type 'Photo' does not conform to protocol 'Decodable'
Type 'Photo' does not conform to protocol 'Encodable'
UIImage
would have beCodable
, and it is not.CLLocationCoordinate2D
would have to beCodable
too. AlsoCodingKeys
would have to be an inner member ofPhoto
. In this case they would not be needed at all. Your best bet is a custom encoding/decoding forUIImage
by conversion toData
(png/jpeg) and probably toString
. – Sulthan