<div dir="ltr">Nice idea but I think the code will look ugly</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 12, 2017 at 1:28 PM, Rafael Guerreiro <span dir="ltr"><<a href="mailto:guerreiro.dev@gmail.com" target="_blank">guerreiro.dev@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You actually need a class to wrap the dictionary.<br>That’s because dictionaries are struct, with copy-on-write.<br><br>With a class, you’ll be able to have it mutable, in a let declaration.<br><div class="gmail_quote"><div><div class="h5"><div dir="ltr">On Mon, Dec 11, 2017 at 11:34 PM Inder Kumar Rathore . via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi All,<div>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.</div><div><br></div><div>e.g.</div><div><br></div><div>class MyClass {</div><div> var myDict = [String : String]()</div><div>}</div><div><br></div><div><br></div><div>I want above variable to be constant and if I make it like below</div><div><br></div><div><div>class MyClass {</div><div> let myDict = [String : String]()</div><div>}</div><div><br></div><div>Then I cann't add key/value in the myDict like</div><div><br></div><div> self.myDict["name"] = "Rathore"</div><div><br></div><div><br></div><div>I know swift and couldn't find anything related to this.</div><div><br></div><div>Can anybody help me?</div><div><br></div><div><br></div><div>If there is no such method of doing it then I would suggest to either use a syntax like</div><div><br></div><div><div>class MyClass {</div><div> const var myDict = [String : String]()</div><div>}</div></div><div><br></div><div>I'm not using <i>final </i>here since that make a var not overridable.</div><div><br></div><div><br></div><div><br></div>-- <br><div class="m_-6237298602579136790m_-9221753829226272694gmail_signature"><div dir="ltr"><font color="#666666">Best regards,</font><div><font color="#666666">Inder Kumar Rathore</font></div></div></div>
</div></div></div></div>
______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
</blockquote></div>
</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>