Synthesized Code for Codable Protocol

Does Xcode support some method by which I can view the code synthesized by the compiler supporting the Codable protocol?


If not, does Xcode maintain intermediate files that contain synthesized code? If so, where can I find these files?


Cheers,

-Patrick

Accepted Reply

No, it's not possible to do this. At a technical level, it's not a big problem to write the code yourself, because the synthesized code is always very straightforward and magic-free. It's no worse than tedious to write your own replacement.


OTOH, it would certainly be good if the synthesized code could be used as a starting point for a given type's custom code, or even the synthesized code could be inspected. It's not easy right now because it's synthesized directly to a compiled form — the compiler doesn't actually produce the source code (AFAIK, which isn't very far, I admit).


You should re-ask this question over on forums.swift.org. It's a known issue there, but if you add your voice to the debate, that increases the chance that the Swift team will feel motivated to implement some solution. Even better, you are free (as is anyone) to get involved and work towards a solution that eventually gets incorporated into the public Swift release.

Replies

No, it's not possible to do this. At a technical level, it's not a big problem to write the code yourself, because the synthesized code is always very straightforward and magic-free. It's no worse than tedious to write your own replacement.


OTOH, it would certainly be good if the synthesized code could be used as a starting point for a given type's custom code, or even the synthesized code could be inspected. It's not easy right now because it's synthesized directly to a compiled form — the compiler doesn't actually produce the source code (AFAIK, which isn't very far, I admit).


You should re-ask this question over on forums.swift.org. It's a known issue there, but if you add your voice to the debate, that increases the chance that the Swift team will feel motivated to implement some solution. Even better, you are free (as is anyone) to get involved and work towards a solution that eventually gets incorporated into the public Swift release.

Thanks for your reply. I started this thread on the Swift Forums:


https://forums.swift.org/t/viewing-synthesized-code/14560?u=patrick_gili


While the replies somewhat provide some useful information, none provide an efficient means of viewing and validating code synthesized by the compiler. This might require putting together a proposal and submitting it.