2023-04-23 13:57:49 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This source file is part of the AmiiboService open source project
|
|
|
|
//
|
|
|
|
// Copyright (c) 2023 Röck+Cöde VoF. and the AmiiboService project authors
|
|
|
|
// Licensed under the EUPL 1.2 or later.
|
|
|
|
//
|
|
|
|
// See LICENSE.txt for license information
|
|
|
|
// See CONTRIBUTORS.txt for the list of AmiiboService project authors
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|