<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 14, 2017, at 12:51 AM, Inder Kumar Rathore . &lt;<a href="mailto:rathore619@gmail.com" class="">rathore619@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div 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);" class=""><span style="color:rgb(194,52,155)" class="">class</span> MyClass {</div><div 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);" class="">&nbsp; <span style="color:rgb(194,52,155)" class="">private</span> <span style="color:rgb(194,52,155)" class="">var</span> myDict = [<span style="color:rgb(0,175,202)" class="">String</span> : <span style="color:rgb(0,175,202)" class="">String</span>]()</div><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" class="">&nbsp;&nbsp;<br class="webkit-block-placeholder"></p><div 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);" class="">&nbsp; <span style="color:rgb(194,52,155)" class="">func</span> addMemebr() {</div><div 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);" class=""><span style="color:rgb(255,255,255)" class="">&nbsp; &nbsp; </span><span style="color:rgb(194,52,155)" class="">self</span><span style="color:rgb(255,255,255)" class="">.</span><span style="color:rgb(147,201,106)" class="">myDict</span><span style="color:rgb(255,255,255)" class="">[</span>"key"<span style="color:rgb(255,255,255)" class="">] = </span>"value"<span style="color:rgb(255,255,255)" class=""> </span><span style="color:rgb(77,191,86)" class="">// Ok for me</span></div><div 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);" class="">&nbsp; }</div><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" class="">&nbsp;&nbsp;<br class="webkit-block-placeholder"></p><div 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);" class="">&nbsp; <span style="color:rgb(194,52,155)" class="">func</span> anotherFunc() {</div><div 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);" class=""><span style="color:rgb(255,255,255)" class="">&nbsp; &nbsp; </span><span style="color:rgb(194,52,155)" class="">self</span><span style="color:rgb(255,255,255)" class="">.</span><span style="color:rgb(147,201,106)" class="">myDict</span><span style="color:rgb(255,255,255)" class=""> = [</span><span style="color:rgb(0,175,202)" class="">String</span><span style="color:rgb(255,255,255)" class=""> : </span><span style="color:rgb(0,175,202)" class="">String</span><span style="color:rgb(255,255,255)" class="">]() </span>// Not okay for me, I don't want any code to do this within the class</div><div 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);" class="">&nbsp; }</div><div 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);" class="">}</div></div></div></blockquote><br class=""></div><div>If you want code to be able to insert, but not delete from or otherwise freely change, the dictionary value, you could provide a wrapper type for myDict that provides a restricted mutation API:</div><div><br class=""></div><div>struct InsertOnlyDictionary {</div><div>&nbsp; private(set) var value = [String: String]()</div><div><br class=""></div><div>&nbsp; mutating func insert(_ k: String, _ v: String) {</div><div>&nbsp; &nbsp; value[k] = v</div><div>&nbsp; }</div><div>}</div><div><br class=""></div><div>// Code outside of InsertOnlyDictionary can read its `value`, but can only modify it by its `insert` API</div><div>class MyClass {</div><div>&nbsp; private var myDict = InsertOnlyDictionary()</div><div><br class=""></div><div>&nbsp; func addMember() {</div><div>&nbsp; &nbsp; self.myDict.insert("key", "value")</div><div>&nbsp; }</div><div>}</div><div><br class=""></div><div>-Joe</div><br class=""></body></html>