<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="">Benjamin,&nbsp;<div class=""><br class=""></div><div class="">It sounds like your concern is that people might write objects that just store everything in a dictionary, instead of declaring typed properties. Correct?<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 7, 2017, at 7:11 AM, Benjamin G via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><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=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div>I think i answered that question many times as well (by masquerading dictionaries as regular classes), but if what i'm saying is simply impossible because of Swift type system even with the new proposal, i'd rather people tell it to me than ask the same question over and over..</div><br class=""></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></div></blockquote><br class=""></div><div>It <i class="">would</i> be possible, in theory, to write a class that used a dictionary as a backing store for all its properties under this proposal. However, the dictionary would have to be typed <font face="Menlo" class="">[String: Any?]</font>, and every property access would be typed <font face="Menlo" class="">Any?</font>. Your code would look like this:</div><div><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="color: rgb(186, 45, 162);" class="">class</span><span style="color: rgb(0, 0, 0);" class=""> MyDynamicObject: </span>DynamicMemberLookupProtocol<span style="color: rgb(0, 0, 0);" class=""> {</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">var</span> storage: [<span style="color: #703daa" class="">String</span>: <span style="color: #ba2da2" class="">Any</span>?] = [:]</div><p style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255); min-height: 13px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #ba2da2" class="">subscript</span>(dynamicMember: <span style="color: #703daa" class="">String</span>) -&gt; <span style="color: #ba2da2" class="">Any</span>? {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">get</span> { <span style="color: #ba2da2" class="">return</span> <span style="color: #4f8187" class="">storage</span>[dynamicMember] }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ba2da2" class="">set</span>(newValue) { <span style="color: #4f8187" class="">storage</span>[dynamicMember] = newValue }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135); background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">let</span><span style="color: #000000" class=""> x: </span>MyDynamicObject<span style="color: #000000" class=""> = ...</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// setting properties is easy!</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">x.name = “Benjamin”</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">x.age = <font color="#272ad8" class="">3</font></div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class="">// using them, though, is hard!</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">var</span> adults: [<span style="color: #703daa" class="">String</span>] = []</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">if</span> x.age <span style="color: #ba2da2" class="">as</span>! <span style="color: #703daa" class="">Int</span> &gt; <span style="color: #272ad8" class="">18</span> {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #4f8187" class="">adults</span>.append(x.name <span style="color: #ba2da2" class="">as</span>! <span style="color: #703daa" class="">String</span>)</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class="">}</div></div></blockquote><div><br class=""></div><div>If you decide to create an object that stores everything in an ‘<font face="Menlo" class="">Any</font>’, Swift is going to force you to use an ‘<font face="Menlo" class="">as</font>’ cast anytime you want to use it. That’s super annoying.</div><div><br class=""></div><div>So yes, it’s possible to create a type that masquerades a dictionary as a regular class. But the ergonomics of doing so are sufficiently frustrating that nobody is likely to do so. Swift makes it easy to declare typed variables here, and the user experience for doing so is vastly improved (code completion, compile-time checking, no more ‘<font face="Menlo" class="">as</font>’ casting, etc).</div><div><br class=""></div><div>So while it’s theoretically possible to do this, I don’t think it’s a concern in practice. The incentives are already in place to encourage doing the “right” thing in this case, even with the possibility of dynamic member lookup.</div><div><br class=""></div><div>-BJ</div></div></body></html>