<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 21, 2017, at 11:00 AM, Colin Barrett via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, Mar 16, 2017 at 3:33 PM Itai Ferber via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><u class="gmail_msg"></u>




<div class="gmail_msg"><div style="font-family:sans-serif" class="gmail_msg"><div style="white-space:normal" class="gmail_msg"><blockquote style="border-left:2px solid #777;color:#777;margin:0 0 5px;padding-left:5px" class="gmail_msg"><p dir="auto" class="gmail_msg"><br class="gmail_msg">
Here's what I mean: Suppose I have a BlogPost model, and I can both fetch and post BlogPosts to a cross-platform web service, and store them locally. But when I fetch and post remotely, I ned to conform to the web service's formats; when I store an instance locally, I have a freer hand in designing my storage, and perhaps need to store some extra metadata. How do you imagine handling that sort of situation? Is the answer simply that I should use two different types?</p>
</blockquote></div>
</div></div><div class="gmail_msg"><div style="font-family:sans-serif" class="gmail_msg"><div style="white-space:normal" class="gmail_msg"><p dir="auto" class="gmail_msg">This is a valid concern, and one that should likely be addressed.</p><p dir="auto" class="gmail_msg">Perhaps the solution is to offer a <code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7" class="gmail_msg">userInfo : [UserInfoKey : Any]</code> (<code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7" class="gmail_msg">UserInfoKey</code> being a <code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7" class="gmail_msg">String</code>-<code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7" class="gmail_msg">RawRepresentable</code> struct or similar) on <code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7" class="gmail_msg">Encoder</code> and <code style="background-color:#f7f7f7;border-radius:3px;margin:0;padding:0 0.4em" bgcolor="#F7F7F7" class="gmail_msg">Decoder</code> set at the top-level to allow passing this type of contextual information from the top level down.</p></div></div></div></blockquote><div class="">&nbsp;</div><div class="">I assumed that in those situations, one would create a wrapper struct,</div><div class=""><br class=""></div><div class="">struct WebBlogModel {</div><div class="">&nbsp; &nbsp; let wrapped: BlogModel</div><div class="">}</div><div class=""><br class=""></div><div class="">probably for the encoding impl that requires more custom work. The implementation of Codable for this struct would then serialize (deserialize) from (to) its wrapped value's properties directly.</div><div class=""><br class=""></div><div class="">Types already provide a means for performing context sensitive implementation selection, I don't think it's necessary to provide another way to do that in Swift. Of course I could very well be wrong :)</div></div></div></div></blockquote><div><br class=""></div><div>Wrappers like this give you a way to <i class="">implement</i>&nbsp;different encoding strategies but they don’t help you identify which strategy to use for a given encoding. &nbsp;You need a user-defined context to do that. &nbsp;Brent has proposed a couple of different designs to facilitate this which are nicer than a user info dictionary.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_quote"><div class=""><br class=""></div><div class="">-Colin</div></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>