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

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -