[SR-7566] Improve handling/synthesis of Protocols that are Codable #50108
Labels
Codable
Area → standard library: `Codable` and co.
compiler
The Swift compiler in itself
improvement
Additional Detail from JIRA
md5: fe10b8d6c86530b0815424131ee13283
Issue Description:
If a Codable Type has a Protocol property that is also Codable, encoding/decoding requires a significant amount of boilerplate code and/or changing the Protocol property to instead be a Type Erasure property.
Root issue being that a Protocol does not conform to itself, so the Protocol property does not itself conform to Codable. This blocks the Codable synthesis of the parent class.
There is also the additional problem of needing to encode/decode unique properties of each Protocol adoptee.
The solutions to this issue are outlined in the excellent answer here:
https://stackoverflow.com/a/44473156/1265393
Opening this improvement ticket for a future version of Swift to hopefully synthesize or otherwise automatically handle Codability of Protocol properties.
Example of issue for playground:
The text was updated successfully, but these errors were encountered: