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
structto aclass - Remove
Hashableconformance - Add
Identifiableconformance - Add
idproperty - Add
idcase - Init
id = UUID() - Identify by
\.idinstead of\.self - remove
.uniquedfrom 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)
}