<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>I think if you can figure that out, you’re halfway to letting protocols conform to themselves.</div><div><br></div><div>(Syntactically, I would probably say that something like “Codable.Self” would read well, but I think that already means something. Maybe the answer will become clearer when we rework the reflection APIs?)<br><br><div id="AppleMailSignature">Sent from my iPhone</div><div><br>On Oct 19, 2017, at 13:13, Itai Ferber <<a href="mailto:iferber@apple.com">iferber@apple.com</a>> wrote:<br><br></div><blockquote type="cite"><div>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">Even then, that wouldn’t necessarily help in the general case. If you decode <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">{"key" : 1}</code> as <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">[String : Codable]</code>, what concrete type would <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">1</code> have? <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">Int</code>? <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">Double</code>? <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">Int8</code>? (Arguments can be made for any one of these, but the key here is that it is inherently ambiguous and there isn’t necessarily a good answer.)</p>
<p dir="auto">On 19 Oct 2017, at 12:57, David Sweeris wrote:</p>
</div>
<div style="white-space:normal"><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px"><blockquote style="border-left:2px solid #777; color:#999; margin:0 0 5px; padding-left:5px; border-left-color:#999"><p dir="auto">On Oct 19, 2017, at 12:50 PM, David Baraff via swift-users <<a href="mailto:swift-users@swift.org">swift-users@swift.org</a>> wrote:<br>
<br>
Yes; this is a case where anywhere in the code base I want to just say<br>
        struct MyNewType : Codable {<br>
                // add codable datatypes<br>
        }<br>
<br>
and don’t want/can’t always go to the centralized place to add it in.<br>
Is there some extension-like trick I can pull off that lets me spread the implementation out over different files/libraries?</p>
</blockquote><p dir="auto">Ah, ok.<br>
<br>
No, I don't think you'll be able to do that until/unless Swift gets more macro/metaprogramming features. Maybe if protocols ever get to conform to themselves? That's a common request, but implementing it is apparently beyond tricky. I'm pretty sure somebody's working on it, but "bigger fish" and all that...<br>
<br>
- Dave Sweeris</p>
</blockquote></div>
<div style="white-space:normal">
</div>
</div>
</div></blockquote></div></body></html>