How does Swift know the Codable type fields don't match the CodingKeys provided?

When I write a Codable structure with mismatched coding keys, the Swift compiler will tell me that it doesn't conform to Decodable. Is this something Swift can do for any similar data structure, or is it something baked into the compiler just for Codable?

struct MyType : Codable {
	var foo: String
	var bar: String
	enum CodingKeys : String, CodingKey {
		case foo = "a_foo"

It looks like there is a function for this validation… but I'm not sure how practical it would be for any arbitrary engineer to roll their own validation without a tool like swift-syntax or something else to read the AST.

1 Like

I figured it had to be in the compiler. Thanks.