<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>"key"<span style="color:rgb(255,255,255)">] = </span>"value"<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'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"><br><div class="gmail_quote">On Tue, Dec 12, 2017 at 10:28 PM, Joe Groff <span dir="ltr"><<a href="mailto:jgroff@apple.com" target="_blank">jgroff@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
> On Dec 11, 2017, at 11:34 PM, Inder Kumar Rathore . via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
><br>
> Hi All,<br>
> Today I was writing code and faced a situation where I need to make a instance variable a const i.e. it shouldn't accept new values from anywhere but the problem is that I want it's content to be mutable.<br>
><br>
> e.g.<br>
><br>
> class MyClass {<br>
> var myDict = [String : String]()<br>
> }<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="HOEnZb"><font color="#888888"><br>
-Joe<br>
<br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_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>
</div>