<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Hello Itai,</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">Sorry for the confusion, but I understood that the following</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature"><blockquote type="cite"><span style="background-color: rgba(255, 255, 255, 0);"><i>To answer your second question, the reason is that using the protocol implies that all encoders and decoders must support anything that conforms to that protocol. We’re not sure this is a reasonable requirement. Many formats do not have any kind of support for arbitrary size integers, for example. Therefore, we felt it was best to limit it to a set of concrete types.</i></span><br></blockquote><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">meant it would actually hinder that kind of transformation or make it more difficult to write custom decoders and encoders. Sorry if I misunderstood that.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">One follow up question: what would happen if inside the JSON mock object you posted I were to remove the 'address' key (in terms of the produced object and how to access its inner properties)? </div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">What would happen if I remove the 'name' one or better if I add another key to the JSON object?</div><br>Sent from my iPhone</div><div><br>On 26 Apr 2017, at 21:28, 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">Hi Goffredo,</p>
<p dir="auto">Unless I'm misunderstanding what you mean here, this is exactly what we're proposing with the API — anything <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">Encodable</code> can encode any type that is <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">Encodable</code> as a nested value:</p>
<pre style="background-color:#F7F7F7; border-radius:5px 5px 5px 5px; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px; color:black" bgcolor="#F7F7F7"><code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0" bgcolor="#F7F7F7"><span style="color: #008800; font-weight: bold">struct</span> <span style="color: #BB0066; font-weight: bold">Person</span> : Codable {
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">name</span>: <span style="color: #007020">String</span>
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">address</span>: Address
}
<span style="color: #008800; font-weight: bold">struct</span> <span style="color: #BB0066; font-weight: bold">Address</span> : Codable {
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">street</span>: <span style="color: #007020">String</span>
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">city</span>: <span style="color: #007020">String</span>
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">state</span>: <span style="color: #007020">String</span>
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">zipCode</span>: <span style="color: #007020">Int</span>
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">country</span>: <span style="color: #007020">String</span>
}
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">address</span> = Address(street: <span style="background-color: #fff0f0">"1 Infinite Loop"</span>, city: <span style="background-color: #fff0f0">"Cupertino"</span>, state: <span style="background-color: #fff0f0">"CA"</span>, zipCode: <span style="color: #0000DD; font-weight: bold">95014</span>, country: <span style="background-color: #fff0f0">"United States"</span>)
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">person</span> = Person(name: <span style="background-color: #fff0f0">"John Doe"</span>, address: address)
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">encoder</span> = JSONEncoder()
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">payload</span> = try encoder.encode(person)
<span style="color: #007020">print</span>(<span style="color: #007020">String</span>(data: payload, encoding: .utf8)<span style="color: #333333">!</span>) <span style="color: #888888">// => {"name": "John Doe", address: {"street": "1 Infinite Loop", ... } }</span>
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">decoder</span> = JSONDecoder()
<span style="color: #008800; font-weight: bold">let</span> <span style="color: #996633">decoded</span> = try decoder.decode(Person.<span style="color: #008800; font-weight: bold">self</span>, from: payload) <span style="color: #888888">// => Person(name: "John Doe", address: ...)</span>
</code></pre>
<p dir="auto">Or have I misunderstood you?</p>
<p dir="auto">— Itai</p>
<p dir="auto">On 26 Apr 2017, at 13:11, Goffredo Marocchi via swift-evolution wrote:</p>
<p dir="auto"></p></div>
<div style="white-space:normal"></div>
<blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px"><div id="558C7C14-AADC-486E-8E7F-C7C0358786AC"><div dir="auto"><div><br><br>Sent from my iPhone</div><div><br>On 26 Apr 2017, at 17:24, Tony Parker via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8">Hi Riley,<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Apr 25, 2017, at 6:11 PM, Riley Testut via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I’m sure this has already been discussed, but why are the methods throwing NSErrors and not Enums? If I’m remembering correctly, the original reason for this was because this was meant to be a part of Foundation. Now that this is in the Standard Library, however, it seems strange that we’re still using NSError.</div><div class=""><br class=""></div><div class="">Second question that again I’m sure was asked and answered already, but: why do we require implementations for each concrete numeric type (Int, Int8, Int16, Float, etc), instead of using protocols (such as the new Integer protocols)?</div></div></div></blockquote><div><br class=""></div>To answer your second question, the reason is that using the protocol implies that all encoders and decoders must support anything that conforms to that protocol. </div></div></blockquote><div><br></div><div>Would this make it easier to transform nested JSON into a nested object/struct? If so it could be useful, very useful.</div><div><br></div><blockquote type="cite"><div><div>We’re not sure this is a reasonable requirement. Many formats do not have any kind of support for arbitrary size integers, for example. Therefore, we felt it was best to limit it to a set of concrete types.</div><div><br class=""></div></div></blockquote><div><br></div><div>I honk we would be missing a trick, unless I am missing something here, that was very powerful in libraries like Mantle for iOS: the ability to translate a nested JSON object (some keys in the JSON object having a JSON object as value, etc...) in an MTLModel subclass composed of other MTLModel subclasses where doing the transformation of the root object would call the right model needed to transform for the child JSON objects.</div><div>Working with Mantle is safe, rugged (it does not cause crashes if the JSON file changes), and allows you to break the problem into chunks and present a coherent simple view to the code that makes use of the instance you created out of the JSON input. Reference: <a href="https://github.com/Mantle/Mantle/blob/master/README.md">https://github.com/Mantle/Mantle/blob/master/README.md</a></div><div><br></div><br><blockquote type="cite"><div><div>We could change our minds on this before we ship Swift 4, if we feel it was the wrong decision. Now that the proposals are accepted we will be landing these branches in master soon, which means everyone has a great chance to try it out and see how it feels in real world usage before it’s final.</div><div><br class=""></div><div>- Tony</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Apr 25, 2017, at 3:59 PM, Douglas Gregor via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Proposal Link: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0166-swift-archival-serialization.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0166-swift-archival-serialization.md</a><div class=""><br class=""></div><div class="">Hello Swift Community,</div><div class=""><br class=""></div><div class="">The review of SE-0166 “Swift Archival & Serialization” ran from April 6...12, 2017. The proposal is <b class="">accepted</b> with some minor modifications. Specifically, the core protocols and types will be sunk down into the Swift standard library for more tight integration with the Swift language and compiler, and the operations specifically involving Foundation’s “Data” type will be removed. The proposal document has been updated with more detail. Thank you everyone for participating in this review!</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Review Manager</div><div class=""><br class=""></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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></div></blockquote>
<div style="white-space:normal">
<blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px">
</blockquote><p dir="auto">_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color:#3983C4">https://lists.swift.org/mailman/listinfo/swift-evolution</a></p>
</div>
<div style="white-space:normal">
</div>
</div>
</div></blockquote></body></html>