<div dir="ltr">What are you going to do about this then?<div><br></div><div>







<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-Apple-converted-space">    </span><span class="gmail-s1" style="color:rgb(186,45,162)">func</span> thirdFunc() {</p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-Apple-converted-space">        </span><span class="gmail-s1" style="color:rgb(186,45,162)">self</span>.<span class="gmail-s2" style="color:rgb(79,129,135)">myDict</span>.<span class="gmail-s3" style="color:rgb(62,30,129)">removeAll</span>()</p>
<p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-Apple-converted-space">    </span>}</p><p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></p><p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)">Is this ok or not? Is it really different from `anotherFunc`?</p><p class="gmail-p1" style="margin:0px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:13px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><br></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 14, 2017 at 10:52 AM, Inder Kumar Rathore . via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(40,43,53)"><span style="color:rgb(194,52,155)">class</span> MyClass {</p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(40,43,53)">  <span style="color:rgb(194,52,155)">private</span> <span style="color:rgb(194,52,155)">var</span> myDict = [<span style="color:rgb(0,175,202)">String</span> : <span style="color:rgb(0,175,202)">String</span>]()</p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(40,43,53);min-height:18px">  </p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(40,43,53)">  <span style="color:rgb(194,52,155)">func</span> addMemebr() {</p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(228,67,71);background-color:rgb(40,43,53)"><span style="color:rgb(255,255,255)">    </span><span style="color:rgb(194,52,155)">self</span><span style="color:rgb(255,255,255)">.</span><span style="color:rgb(147,201,106)">myDict</span><span style="color:rgb(255,255,255)">[</span>&quot;key&quot;<span style="color:rgb(255,255,255)">] = </span>&quot;value&quot;<span style="color:rgb(255,255,255)"> </span><span style="color:rgb(77,191,86)">// Ok for me</span></p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(40,43,53)">  }</p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(40,43,53);min-height:18px">  </p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(40,43,53)">  <span style="color:rgb(194,52,155)">func</span> anotherFunc() {</p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(77,191,86);background-color:rgb(40,43,53)"><span style="color:rgb(255,255,255)">    </span><span style="color:rgb(194,52,155)">self</span><span style="color:rgb(255,255,255)">.</span><span style="color:rgb(147,201,106)">myDict</span><span style="color:rgb(255,255,255)"> = [</span><span style="color:rgb(0,175,202)">String</span><span style="color:rgb(255,255,255)"> : </span><span style="color:rgb(0,175,202)">String</span><span style="color:rgb(255,255,255)">]() </span>// Not okay for me, I don&#39;t want any code to do this within the class</p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(40,43,53)">  }</p>
<p style="margin:0px;font-stretch:normal;font-size:15px;line-height:normal;font-family:Menlo;color:rgb(255,255,255);background-color:rgb(40,43,53)">}</p></div><div class="gmail_extra"><span class=""><br><div class="gmail_quote">On Tue, Dec 12, 2017 at 10:28 PM, Joe Groff <span dir="ltr">&lt;<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
<br>
&gt; On Dec 11, 2017, at 11:34 PM, Inder Kumar Rathore . via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi All,<br>
&gt; Today I was writing code and faced a situation where I need to make a instance variable a const i.e. it shouldn&#39;t accept new values from anywhere but the problem is that I want it&#39;s content to be mutable.<br>
&gt;<br>
&gt; e.g.<br>
&gt;<br>
&gt; class MyClass {<br>
&gt;   var myDict = [String : String]()<br>
&gt; }<br>
<br>
</span>You can do this by making the setter private:<br>
<br>
class MyClass {<br>
  private(set) var myDict = [String: String]()<br>
}<br>
<br>
This will allow declarations inside the MyClass definition to modify myDict, but not code outside the class definition.<br>
<span class="m_-352780651292667084HOEnZb"><font color="#888888"><br>
-Joe<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div></span><span class="">-- <br><div class="m_-352780651292667084gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><font color="#666666">Best regards,</font><div><font color="#666666">Inder Kumar Rathore</font></div></div></div>
</span></div>
<br>______________________________<wbr>_________________<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/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>