Your code does not compile due to several errors / typos.
To decode an array Intwrite
struct Something: Decodable {
var value: [Int]
enum CodingKeys: String, CodingKey {
case value
}
init (from decoder :Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
value = try container.decode([Int].self, forKey: .value)
}
}
But if the sample code in the question represents the whole structure, it can be reduced to
struct Something: Decodable {
let value: [Int]
}
since the initializer and CodingKeyscan be deduced.
source
share