We’re still making some behind the scenes changes so that we can cache api responses using CoreData. Today we’ll change Pod from a struct
to a class
.
- Change Pod form a
struct
to aclass
- Remove
Hashable
conformance - Add
Identifiable
conformance - Add
id
property - Add
id
case - Init
id = UUID()
- Identify by
\.id
instead of\.self
- remove
.uniqued
from List - Add required init
let id: UUID
...
case id
...
id = UUID()
ForEach(pods, id: \.id) { pod in
required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
copyright = try container.decodeIfPresent(String.self, forKey: .copyright)
date = try container.decodeIfPresent(Date.self, forKey: .date)
explanation = try container.decode(String.self, forKey: .explanation)
hdurl = try container.decodeIfPresent(URL.self, forKey: .hdurl)
url = try container.decodeIfPresent(URL.self, forKey: .url)
thumbnailUrl = try container.decodeIfPresent(URL.self, forKey: .thumbnailUrl)
title = try container.decode(String.self, forKey: .title)
serviceVersion = try container.decode(String.self, forKey: .serviceVersion)
mediaType = try container.decode(String.self, forKey: .mediaType)
}