<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Oh! Yeah, my bad... You are correct; I'd started thinking like I was on -evolution instead of -users.<div class=""><br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 19, 2017, at 1:29 PM, Itai Ferber <<a href="mailto:iferber@apple.com" class="">iferber@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" class="">
<div class="">
<div style="font-family:sans-serif" class=""><div style="white-space:normal" class=""><p dir="auto" class="">Mm, the point I’m trying to get at here is that JSON is inherently untyped while Swift is strongly typed, and the two don’t line up.<br class="">
It doesn’t really make sense to ask to decode an existential because there’s not enough type information to influence what you get back.</p><p dir="auto" class="">On 19 Oct 2017, at 13:20, David Sweeris wrote:</p>
</div>
<blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px" class=""><div id="7C1D4686-733E-42FA-902B-BB3B23DA2A7D" class=""><div dir="auto" class=""><div class="">I think if you can figure that out, you’re halfway to letting protocols conform to themselves.</div><div class=""><br class=""></div><div class="">(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 class=""><br class=""><div class="">Sent from my iPhone</div><div class=""><br class="">On Oct 19, 2017, at 13:13, Itai Ferber <<a href="mailto:iferber@apple.com" class="">iferber@apple.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" class="">
<div style="font-family:sans-serif" class=""><div style="white-space:normal" class=""><p dir="auto" class="">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" class="">{"key" : 1}</code> as <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">[String : Codable]</code>, what concrete type would <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">1</code> have? <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">Int</code>? <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">Double</code>? <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7" class="">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" class="">On 19 Oct 2017, at 12:57, David Sweeris wrote:</p>
</div>
<div style="white-space:normal" class=""><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px" class=""><blockquote style="border-left:2px solid #777; color:#999; margin:0 0 5px; padding-left:5px; border-left-color:#999" class=""><p dir="auto" class="">On Oct 19, 2017, at 12:50 PM, David Baraff via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class="">
<br class="">
Yes; this is a case where anywhere in the code base I want to just say<br class="">
        struct MyNewType : Codable {<br class="">
                // add codable datatypes<br class="">
        }<br class="">
<br class="">
and don’t want/can’t always go to the centralized place to add it in.<br class="">
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" class="">Ah, ok.<br class="">
<br class="">
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 class="">
<br class="">
- Dave Sweeris</p>
</blockquote></div>
<div style="white-space:normal" class="">
</div>
</div>
</div></blockquote></div></div></div></blockquote>
<div style="white-space:normal" class=""><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px" class="">
</blockquote></div>
</div>
</div>
</div></blockquote></div><br class=""></div></div></body></html>