I have this protocol,
protocol PaginableItem {
var resultType: ResultType { get set }
}
with a single property of an enum type,
enum ResultType: String, Codable {
case photo = "PHOTO"
case baseItem = "BASEITEM"
case new = "NEW"
}
I also have 3 different structs and classes with conforms to PaginableItem
and a class with some PaginableItems
,
final class TimelineModel: Codable {
let stream: String
let participants: String
let header1: PaginableList
let header2: PaginableList
let items: PaginableList
}
final class PaginableList: Codable {
let data: [PaginableItem]
let pagination: Pagination
}
I'm trying to cache TimelineModel
using Swift 4 Codable
, but I'm not sure the best way to do that. Xcode is complaining about PaginableItem
not conforming to Codable
.
It is mandatory to implement init(from decoder: Decoder) throws
and encode(to encoder: Encoder) throws
in ResultType
?
Must PaginableItem
implement Codable
also?