<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">Hi James,</p>

<p dir="auto">Good catch. This is a holdover from an older version of the proposal, and is now a typo.<br>
It should be <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">var container</code> — the container can be a <code style="background-color:#F7F7F7; border-radius:3px; margin:0; padding:0 0.4em" bgcolor="#F7F7F7">struct</code>, and shouldn’t require reference semantics.</p>

<p dir="auto">— Itai</p>

<p dir="auto">On 8 Jun 2017, at 7:51, James Froggatt via swift-evolution wrote:</p>

</div>
<div style="white-space:normal"><blockquote style="border-left:2px solid #777; color:#777; margin:0 0 5px; padding-left:5px"><p dir="auto">I've just been trying out the new Coding protocol, and was rather surprised when trying to implement the `encode(to encoder: Encoder)` method.<br>
<br>
The Swift evolution proposal provides the following example code:<br>
<br>
    public func encode(to encoder: Encoder) throws {<br>
        // Generic keyed encoder gives type-safe key access: cannot encode with keys of the wrong type.<br>
        let container = encoder.container(keyedBy: CodingKeys.self)<br>
<br>
        // The encoder is generic on the key -- free key autocompletion here.<br>
        try container.encode(latitude, forKey: .latitude)<br>
        try container.encode(longitude, forKey: .longitude)<br>
    }<br>
<br>
<br>
Here, container is stored as a `let` value, and uses reference semantics, while the proposal also clearly lists these `encode` methods as mutating. With the current implementation of the proposal, the container must be stored as a `var`, which leads to code like the following:<br>
<br>
    var container = encoder.singleValueContainer()<br>
    try container.encode(data)<br>
<br>
This clearly wont work as expected if the container were to have value semantics, and writing code like this feels plain wrong. Is SE-0166 really intended to work with referrence-type encoders only?<br>
_______________________________________________<br>
swift-evolution mailing list<br>
swift-evolution@swift.org<br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color:#777">https://lists.swift.org/mailman/listinfo/swift-evolution</a></p>
</blockquote></div>
<div style="white-space:normal">
</div>
</div>
</body>
</html>