<div dir="ltr"><div class="gmail_default"><font face="georgia, serif">Howard is almost right.</font><br></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Protocol A means the ring variable must have a getter. For the setter, you can have it or not. Both won't violate the conformance of the Protocol A.</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">Actually, you can write as </font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">protocol B:A { </font></div><div class="gmail_default"><font face="georgia, serif">var ring:String { get set }</font></div><div class="gmail_default"><font face="georgia, serif">}</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">The is more for the last line</font></div><div class="gmail_default"><span style="color:rgb(0,132,0);font-family:Menlo;font-size:11px">// (x as A).ring = "</span><span style="color:rgb(0,132,0);font-size:11px;line-height:normal;font-family:'Apple Color Emoji'">🔔</span><span style="color:rgb(0,132,0);font-family:Menlo;font-size:11px">" Error, A doesn't have set</span></div><div class="gmail_default"><br></div><div class="gmail_default"><font face="georgia, serif">You will find more that </font></div><div class="gmail_default"><font face="georgia, serif">(x as B).ring = "1" <br></font></div><div class="gmail_default"><font face="georgia, serif">doesn't work either. The reason is that (x as B) is a let by default.</font></div><div class="gmail_default"><font face="georgia, serif"><br></font></div><div class="gmail_default"><font face="georgia, serif">You need do </font></div><div class="gmail_default"><div class="gmail_default">var b = x as B</div><div class="gmail_default">b.ring = "1"</div><div class="gmail_default"><br></div><div class="gmail_default">Above works.</div><div class="gmail_default"><br></div><div class="gmail_default">zhaoxin</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 9, 2016 at 10:19 AM, Howard Lovatt via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I don’t really get what you are driving at. If I rework your example so that it runs:<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)">//<span style="line-height:normal;font-family:'Apple Color Emoji'">💍</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">protocol<span style="color:#000000"> A {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">var</span> ring: <span style="color:#703daa">String</span> { <span style="color:#bb2ca2">get</span> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)">//<span style="line-height:normal;font-family:'Apple Color Emoji'">🔔</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(187,44,162)">protocol<span style="color:#000000"> B {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">var</span> ring: <span style="color:#703daa">String</span> { <span style="color:#bb2ca2">get</span> <span style="color:#bb2ca2">set</span> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">class</span> X: <span style="color:#4f8187">A</span>, <span style="color:#4f8187">B</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">var</span> _ring = <span style="color:#d12f1b">"</span><span style="line-height:normal;font-family:'Apple Color Emoji';color:rgb(209,47,27)">💍</span><span style="color:#d12f1b">"</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">var</span> ring: <span style="color:#703daa">String</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">get</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">return</span> <span style="color:#4f8187">_ring</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">set</span> {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:#bb2ca2">self</span>.<span style="color:#4f8187">_ring</span> = newValue</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:#bb2ca2">let</span> x = <span style="color:#4f8187">X</span>()</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:#000000">(</span>x<span style="color:#000000"> </span><span style="color:#bb2ca2">as</span><span style="color:#000000"> </span>A<span style="color:#000000">).</span>ring<span style="color:#000000"> </span><span style="color:#008400">// </span><span style="line-height:normal;font-family:'Apple Color Emoji';color:rgb(0,132,0)">💍</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:#000000">(</span>x<span style="color:#000000"> </span><span style="color:#bb2ca2">as</span><span style="color:#000000"> </span>B<span style="color:#000000">).</span>ring<span style="color:#000000"> </span><span style="color:#008400">// </span><span style="line-height:normal;font-family:'Apple Color Emoji';color:rgb(0,132,0)">💍</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:#4f8187">x</span><span style="color:#000000">.</span><span style="color:#4f8187">ring</span><span style="color:#000000"> </span>// <span style="line-height:normal;font-family:'Apple Color Emoji'">💍</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)">x<span style="color:#000000">.</span>ring<span style="color:#000000"> = </span><span style="color:#d12f1b">"</span><span style="line-height:normal;font-family:'Apple Color Emoji';color:rgb(209,47,27)">🔔</span><span style="color:#d12f1b">"</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="color:#4f8187">x</span><span style="color:#000000">.</span><span style="color:#4f8187">ring</span><span style="color:#000000"> </span>// <span style="line-height:normal;font-family:'Apple Color Emoji'">🔔</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)">// (x as A).ring = "<span style="line-height:normal;font-family:'Apple Color Emoji'">🔔</span>" Error, A doesn't have set</div><div><br></div><div>Then the behaviour is exactly what I would expect.</div>
<br><div><blockquote type="cite"><div>On 7 Jan 2016, at 9:18 PM, Grzegorz Leszek via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div>I suggest compile warning if one classes/structs/enums implements<br>protocols with the same name.<br>It could lead to confusions, when methods of those protocols will mean<br>different things.<br>It will force to implement parent protocol with shared methods or<br>change method in one of the protocols.<br>Below is an example.<br>Regards,<br>Greg<br><br>//💍<br>protocol A {<br> var ring: String { get }<br>}<br><br>//🔔<br>protocol B {<br> var ring: String { get set }<br>}<br><br>class X: A, B {<br> var ring: String {<br> get {<br> return "💍"<br> }<br> set {<br> self.ring = newValue<br> }<br> }<br>}<br>let x = X()<br>let somewhereInTheProject = "\(x.ring) the bell"<br>x.ring = "🔔" // ERROR!<br>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></div></blockquote></div><br></div>
<img alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><br>Owen Zhao<br></div></div></div>
</div>