Swift Playground for Exploring Swift4 Codables for JSON Parsing
- Xcode 9 and above
- Swift 4
- Open
SwiftCodables.playgroundin Xcode - Start with
Toc.xcplaygroundpage which from where you can navigate to the other playground pages. Make sure you check theRender Documentationcheckbox.
Examples demonstrating transformation between JSON and Swift native types using swift4 Codables. Each chapter looks at various use cases.
- The Basics
- The examples introduce the Swift Encodable and Decodable protocols
- Date
- The example discuss the use of built in
Dateencoders/decoders
- The example discuss the use of built in
- Simple Custom Codable Type
- The examples discuss the use of nested
Codabletypes
- The examples discuss the use of nested
- Introduction to Codable Keys
- The examples introduce the
CodableKeyprotocol and how you can use it to specify the mapping of JSON-native properties
- The examples introduce the
- Containers
- The examples introduce the concept of
ContainersincludeingKeyedContainer,UnkeyedContainerandValueContainer
- The examples introduce the concept of
- Changing Types
- The examples demonstrate how you can change the type of a property to an appropriate native type when it is tranformed to a swift type and back
- Flattening Types
- The examples demonstrate how you can flatten a nested JSON object when converting to native type
- Associative Enums
- The examples demonstrate the encoding / decoding of a swift associative enum type to correpsonding JSON types
- Subclasses
- The examples demonstrate the encoding/decoding of native subclasses to corresponding JSON types
- Dynamic Coding Keys
- The examples demonstrate the encoding / decoding JSON objects that hold dynamic set of keys
- Context
- The examples demonstrate the use of context data for encoding/decoding
- All Together
- A more complete example that puts together all the concepts showcased in previous examples

