CodableWithConfiguration
When a type conforms to either
EncodableWithConfiguration
orDecodableWithConfiguration
, it requires an additional configuration value to be passed when either encoding or decoding it (and the compiler will enforce that requirement).[…]
CodableWithConfiguration
is really quite useful when using Swift’s built-in serialization API to encode and decode types that require additional data in order to be initialized, without having to resort to modeling required data as optional, or having to define additional types that are only ever used for decoding purposes.
It’s a shame there’s no way to avoid the boilerplate of encoding/decoding all the properties that don’t come from the configuration.
Previously:
- The Future of Swift Serialization and Deserialization APIs
- Serializing Heterogenous Arrays With Codable
- Encoding and Decoding References with Codable
- Codextended: Extension for Swift’s Codable
- Even More About Swift’s Codable
- Deep Codable