<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="gmail_signature"><div dir="ltr"><font color="#666666">Best regards,</font><div><font color="#666666">Inder Kumar Rathore</font></div></div></div>
</div></div>