Thursday, July 3, 2025

CodableWithConfiguration

John Sundell:

When a type conforms to either EncodableWithConfiguration or DecodableWithConfiguration, 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:

Comments RSS · Twitter · Mastodon

Leave a Comment