If you've ever wondered why I think "Codable" is a terrible #Swiftlang API (despite how convenient it can be), here's a glimpse into my brain: https://forums.swift.org/t/the-future-of-serialization-deserialization-apis/78585/10
The future of serialization & deserialization APIs

I think this was by design… that Coding was meant for well-formed data. NSJSONSerialization and NSPropertyListSerialization were the more correct choice for data that was not well formed.

Swift Forums
@davedelong Hopefully they take this feedback into account, though I fear it’s too late for the Swift team to consider new serialization abstractions.

@davedelong, they mention @rust #Serde framework, so they are not too far from your idea.

“The Serde ecosystem consists of data structures that know how to serialize and deserialize themselves along with data formats that know how to serialize and deserialize other things.”

@davedelong I don’t think it is terrible. Can we do better now with hindsight and better tools? Yes: 💯! Remember what we had before Codable? NSCoder and NSKeyedArchiver

@phausler It's adequate for a lot of use cases, but being built around the wrong abstraction has meant years of proposals to work around that with CodingKeyRepresentable, CodableWithConfiguration, etc. Couple that with how quickly you fall off a cliff if you stray from the Happy Path and it quickly loses its lustre.

And yes, I miss NSKeyedArchiver. We should bring it back, and I say as much to Kevin in the thread.

@phausler @davedelong I think Codable is great, it’s made serialisation trivial.

I’m aware of some of the shortcomings and I wish we could discuss them without harsh judgement of the status quo 😞

@finestructure @phausler @davedelong Serialization is not trivial and Codable didn’t change that. 🤷‍♀️

@helge @finestructure @phausler @davedelong

Codable did not try to change it! What a missed opportunity…

@phausler NSCoder/NSArchiver was actually pretty good for what it was intended for, archiving object graphs. How can I do that today? SwiftData? 🙈

@phausler @davedelong

NSKeyedArchive and friends was a honest, transparent stuff. I hate the Coding black-boxiness! And besides all Dave’s criticism, it is outrageously slow! Dum implementation for dummies.