<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="">Le 11 déc. 2015 à 20:34, Slava Pestov via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">For this reason I’m in favor of going in the opposite direction, and prohibiting classes from conforming to protocols with mutating requirements.</div></div></blockquote><br class=""></div><div>This would go too far.</div><div><br class=""></div><div>It’s common to write a protocol with mutating methods just because the protocol designer expects that some adopting structs may want to mutate in their implementation. And in this case the goal of the protocol designer is certainly not to limit the protocol adoption to structs.</div><div><br class=""></div><div>Here is an example:</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>protocol DatabaseFetchable {</div><div><span class="Apple-tab-span" style="white-space: pre;">        </span>&nbsp; mutating func awakeFromFetch()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>extension DatabaseFetchable {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; func fetch() -&gt; Self {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; var value = /* details omitted */</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; value.awakeFromFetch()</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp; &nbsp; return value</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>&nbsp;&nbsp;}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br class=""></div><div>The protocol does not care at all if awakeFromFetch mutates or not. But the protocol designer does: if the awakeFromFetch method were not declared mutating, many structs could simply not adopt it.</div><div><br class=""></div><div>Gwendal Roué</div><div><br class=""></div></body></html>