Friday, June 30, 2017

Swift 4: JSON With Encoder and Encodable

Greg Heo:

Rather than pore through all the source code for encoding and decoding, let’s take a different approach and step through a simple example: how does a single Int instance wind its way through JSONEncoder and become JSON data?

[…]

To summarize: our Swift values get turned into their Foundation object equivalents by JSONEncoder and friends, then these objects get JSON-ified by JSONSerialization.

[…]

Now what about the reverse, decoding? And how can you write custom encoders and decoders for formats other than JSON, say protocol buffers? Stay tuned for more, or why not dig into the code and see what you find?

2 Comments RSS · Twitter


[…] Peephole for “as” Casts, Swift 4: Synthesizing Equatable and Hashable Conformance, Swift 4: JSON With Encoder and Encodable, Swift 4 String Manifesto, Provide Custom Collections for Dictionary Keys and […]


[…] Previously: Swift 4: JSON With Encoder and Encodable. […]

Leave a Comment