I am new in Swift4. I am trying to use Codable to make my struct type object encodable & decodable to JSON.
Here is my struct Product:
// I declare it to conform to codable
public struct Product: Codable {
public let name: String
public var isSold: Bool
public let icon: UIImage // problem is here
…
// I have excluded 'icon' from codable properties
enum CodingKeys: String, CodingKey {
case name
case isSold = “is_sold”
}
}
Compiler tells me error : 'UIImage’ doesn’t conform to ‘Decodable’, but I have defined CodingKeys which is supposed to tell which properties are wished to be codable, and I have excluded the UIImage property.
I thought this way the compiler wouldn't complain that UIImage type, but it still complains. How to get rid of this error?