<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Ugliness is preferable to the alternative of impossibility because what you are trying to do and the semantics of the type you are trying to do it with are irreconcilably and mutually exclusive.<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 12, 2017, at 12:00 AM, Inder Kumar Rathore . via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Nice idea but I think the code will look ugly</div><div class="gmail_extra" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class="gmail_quote">On Tue, Dec 12, 2017 at 1:28 PM, Rafael Guerreiro<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:guerreiro.dev@gmail.com" target="_blank" class="">guerreiro.dev@gmail.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">You actually need a class to wrap the dictionary.<br class="">That’s because dictionaries are struct, with copy-on-write.<br class=""><br class="">With a class, you’ll be able to have it mutable, in a let declaration.<br class=""><div class="gmail_quote"><div class=""><div class="h5"><div dir="ltr" class="">On Mon, Dec 11, 2017 at 11:34 PM Inder Kumar Rathore . via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div></div></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class=""><div class="h5"><div dir="ltr" class="">Hi All,<div class="">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 class=""><br class=""></div><div class="">e.g.</div><div class=""><br class=""></div><div class="">class MyClass {</div><div class=""> <span class="Apple-converted-space"> </span>var myDict = [String : String]()</div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I want above variable to be constant and if I make it like below</div><div class=""><br class=""></div><div class=""><div class="">class MyClass {</div><div class=""> <span class="Apple-converted-space"> </span>let myDict = [String : String]()</div><div class="">}</div><div class=""><br class=""></div><div class="">Then I cann't add key/value in the myDict like</div><div class=""><br class=""></div><div class=""> self.myDict["name"] = "Rathore"</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I know swift and couldn't find anything related to this.</div><div class=""><br class=""></div><div class="">Can anybody help me?</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">If there is no such method of doing it then I would suggest to either use a syntax like</div><div class=""><br class=""></div><div class=""><div class="">class MyClass {</div><div class=""> <span class="Apple-converted-space"> </span>const var myDict = [String : String]()</div><div class="">}</div></div><div class=""><br class=""></div><div class="">I'm not using<span class="Apple-converted-space"> </span><i class="">final<span class="Apple-converted-space"> </span></i>here since that make a var not overridable.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div class="m_-6237298602579136790m_-9221753829226272694gmail_signature"><div dir="ltr" class=""><font color="#666666" class="">Best regards,</font><div class=""><font color="#666666" class="">Inder Kumar Rathore</font></div></div></div></div></div></div></div>______________________________<wbr class="">_________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class=""></blockquote></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><font color="#666666" class="">Best regards,</font><div class=""><font color="#666666" class="">Inder Kumar Rathore</font></div></div></div></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>