I love using Marshal as it is much simpler than swift's Codable. But very often I want to serialize and deserialize my objects using the same keys. So I was always creating enums so the keys are kept on a single place.
And I was wondering why I need to write that when conforming to Codable does that for me automatically. So i thought it would be nice if Marshal supported using CodingKeys.
I had two ideas
add variants of value(for:) methods with CodingKey variant
substitute KeyType for CodingKey
I went for variant 2 as it made more sense for me. At first I wanted to say that every CodingKey is also a KeyType as KeyType requires just a stringValue which is a subset of what CodingKey requires. This was no way as the compiler doesn't allow protocol inheritace in this way.
Well then I removed custom KeyType and converted it to CodingKey.
Hello,
I love using Marshal as it is much simpler than swift's
Codable
. But very often I want to serialize and deserialize my objects using the same keys. So I was always creating enums so the keys are kept on a single place.And I was wondering why I need to write that when conforming to
Codable
does that for me automatically. So i thought it would be nice if Marshal supported usingCodingKeys
.I had two ideas
value(for:)
methods withCodingKey
variantKeyType
forCodingKey
I went for variant 2 as it made more sense for me. At first I wanted to say that every
CodingKey
is also aKeyType
asKeyType
requires just astringValue
which is a subset of whatCodingKey
requires. This was no way as the compiler doesn't allow protocol inheritace in this way.Well then I removed custom
KeyType
and converted it toCodingKey
.