How to manually decode an an array in swift 4 Codable? -
here code. not know set value to. has done manually because real structure more complex example.
any please?
struct something: decodable { value: [int] enum codingkeys: string, codingkeys { case value } init (from decoder :decoder) { let container = try decoder.container(keyedby: codingkeys.self) value = ??? // < --- put here? } }
your code doesn't compile due few mistakes / typos.
to decode array of int
write
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) } }
Comments
Post a Comment