28 lines
589 B
Swift
28 lines
589 B
Swift
|
struct Result<Model: Decodable> {
|
||
|
let items: [Model]
|
||
|
}
|
||
|
|
||
|
// MARK: - Decodable
|
||
|
|
||
|
extension Result: Decodable {
|
||
|
|
||
|
// MARK: Enumerations
|
||
|
|
||
|
enum CodingKeys: String, CodingKey {
|
||
|
case items = "amiibo"
|
||
|
}
|
||
|
|
||
|
// MARK: Initialisers
|
||
|
|
||
|
init(from decoder: Decoder) throws {
|
||
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||
|
|
||
|
do {
|
||
|
self.items = try container.decode([Model].self, forKey: .items)
|
||
|
} catch {
|
||
|
self.items = [try container.decode(Model.self, forKey: .items)]
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|