Hi Frederick, Nice to meet you.
I dig a little bit deeper in the Swift 5.5 implementation, downloading Xcode 13.4 (still in beta) to run some tests.
What I could see it's exactly what is documented in the proposal linked to the article: https://github.com/apple/swift-evolution/blob/main/proposals/0295-codable-synthesis-for-enums-with-associated-values.md
To show you an example, consider this object, using the same elements of the article:
https://gist.github.com/cipolleschi/37ea5355fffc28b879f84f9ecfda62ec
Is encoded into this json:
https://gist.github.com/cipolleschi/5e9bf09fea38d05902d9458f0c82724b
A couple of considerations:
- enum cases are used as keys and they don't introduce an additional field called `type`.
- if the associated value of the enum does not have a label, it is automatically mapped to an "_n" key, where n is the ordinal in the list of associated values.
Given these two constraints, I don't think we could use the automatically synthesised Codable when it comes to communicate with a backend. The server should return the content in a format that is either inefficient, not human understandable and somehow unnatural for how we are used to write backends.
However, this new feature may become handy to save complex models locally, to store the state of the app so we can restore when it is opened, for example.
As usual, we should pick the right tool for the right situation! ;)