Javier Cicchelli a0dcdf7673 [Tweaks] Models (#5)
This PR contains the work done to make improvements to the existing models.

To provide further details about the work done:
- [x] moved the `games3DS`, `gamesWiiU` and `gamesSwitch` properties from the `Amiibo` model to their own `Games` child model;
- [x] improved the decoding of the `Result` model.

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: #5
2023-04-21 21:47:55 +00:00

28 lines
581 B
Swift

struct Result<Model: Decodable> {
let items: [Model]
}
// MARK: - Decodable
extension Result: Decodable {
// MARK: Enumerations
enum CodingKeys: String, CodingKey {
case 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: .amiibo)
} catch {
self.items = [try container.decode(Model.self, forKey: .amiibo)]
}
}
}