Encoding and Decoding in Swift
summary
Explains how Swift’s Codable actually works with concrete code: shows the Encoder vs JSONEncoder API mismatch, walks through nested keyed and unkeyed containers and single-value containers, demonstrates renaming keys, flattening arrays into strings, and custom encode/decode implementations, and describes building a custom encoder/decoder for MongoDB including the private _JSONEncoder/_JSONEncodingStorage-backed NS arrays/dictionaries approach. Covers practical limits — performance and boilerplate — and gives concrete examples that compile and round‑trip JSON.
AI-written summary · about
chapters (21)
- 0:00Start
- 1:05What Encoding and Decoding Actually Are
- 1:38Decoding
- 4:19Format Agnostic
- 4:36Decodable Protocol
- 5:58Json Encoder
- 7:04Json Decoder
- 8:11Rename a Key
- 8:33Coding Keys
- 8:59Custom Implementation
- 10:12The Encoder Protocol
- 11:33Recursive Case
- 12:36Keyed Container
- 15:20Nested Container
- 16:42Array Implementation of the Encode Method
- 18:15Flattening Data
- 19:08Encode Method
- 21:05Main Takeaways
- 21:32Writing Your Own Encoders and Decoders
- 23:17Json Encoding Storage
- 25:52Limitations








