This week, let’s explore a few different techniques for handling dynamic, polymorphic model data, in ways that still leans into Swift’s strong emphasis on type-safety.
This week, let’s take a look at a few different ways that we can tweak the way Swift’s Codable API works, and how doing so can let us bridge many of the differences between our Swift types and the serialized data used to represent them — without having to fall back to implementing all of our serialization code from scratch.
Introduced in Swift 4, the Codable API enables us to leverage the compiler in order to generate much of the code needed to encode and decode data to/from a serialized format, like JSON. Let’s take a look at how to use it.
Type inference is a key feature of the Swift type system and plays a big part in the syntax of the language - making it less verbose by eliminating the need for manual type annotations where the compiler itself can infer the types of various values.