Codable && Tuple
During my learning of Swift, many interesting things I will find. Codable is one of them.
Today, I defined a model with a tuple type, then Xcode told me some error. Codes may like as below.

You may want Xcode automatically complete all the codable stuff. However, life is hard. Codes like these can even not be compiled. Xcode will tell you name cannot be synthesize the Person because of the FullName.
|
|
So, We know that if a struct or class is codable implicitly, it must not contain properties which are not codable. Tuple is one of them.
Some people argue that why tuple cannot be designed as a codable type? Yeah, the hope is that tuples could conform to protocols in future. This is covered in the generics manifesto as “Extensions of Structural Types 28”.
Extensions of structural types Currently, only nominal types (classes, structs, enums, protocols) can be extended. One could imagine extending structural types–particularly tuple types–to allow them to, e.g., conform to protocols. For example, pulling together variadic generics, parameterized extensions, and conditional conformances, one could express “a tuple type is Equatable if all of its element types are Equatable”:
|
|
There are some natural bounds here: one would need to have actual structural types. One would not be able to extend every type:
|
|
And before you think you’re cleverly making it possible to have a conditional conformance that makes every type T that conforms to protocol P also conform to protocol Q, see the section “Conditional conformances via protocol extensions”, below:
|
|
So for now, you have to synthesize the tuple type by yourself.
