Riccardo Cipolleschi
1 min readJul 29, 2021

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! ;)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Riccardo Cipolleschi
Riccardo Cipolleschi

Written by Riccardo Cipolleschi

Hey there, I’m Riccardo. Software engineer at Meta. I have a passion for iOS and I love to share my knowledge with others.

No responses yet

Write a response