2023-04-21 18:16:38 +00:00
|
|
|
struct Result<Model: Decodable> {
|
|
|
|
let items: [Model]
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Decodable
|
|
|
|
|
|
|
|
extension Result: Decodable {
|
|
|
|
|
|
|
|
// MARK: Enumerations
|
|
|
|
|
|
|
|
enum CodingKeys: String, CodingKey {
|
2023-04-21 21:47:55 +00:00
|
|
|
case amiibo
|
2023-04-21 18:16:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Initialisers
|
|
|
|
|
|
|
|
init(from decoder: Decoder) throws {
|
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
|
|
|
|
do {
|
2023-04-21 21:47:55 +00:00
|
|
|
self.items = try container.decode([Model].self, forKey: .amiibo)
|
2023-04-21 18:16:38 +00:00
|
|
|
} catch {
|
2023-04-21 21:47:55 +00:00
|
|
|
self.items = [try container.decode(Model.self, forKey: .amiibo)]
|
2023-04-21 18:16:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|