Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Photo: Codable {
- let hasShadow: Bool
- let image: UIImage?
- enum CodingKeys: String, CodingKey {
- case `self`, hasShadow, image
- }
- init(hasShadow: Bool, image: UIImage?) {
- self.hasShadow = hasShadow
- self.image = image
- }
- init(from decoder: Decoder) throws {
- let container = try decoder.container(keyedBy: CodingKeys.self)
- hasShadow = try container.decode(Bool.self, forKey: .hasShadow)
- // This fails
- image = try container.decode(UIImage?.self, forKey: .image)
- }
- func encode(to encoder: Encoder) throws {
- var container = encoder.container(keyedBy: CodingKeys.self)
- try container.encode(hasShadow, forKey: .hasShadow)
- // This also fails
- try container.encode(image, forKey: .image)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement