<div dir="ltr">+1. Side effects can be eliminated through code migration if a suitable property name is chosen. Perhaps `staticType` to continue in the vein of `dynamicType`? <div><br></div><div>Main detractor is that creating more keywords isn&#39;t necessarily a good thing.</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 15, 2015 at 11:19 AM Brandon Knope via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><span></span></div><div><span></span>One area of swift that is really not clear to me is when you want to use the type of a class, struct, enum, etc as a value. </div><div><br></div><div>Metatyping is explained here: <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-XID_1022" target="_blank">https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Types.html#//apple_ref/doc/uid/TP40014097-CH31-XID_1022</a></div><div><br></div><div>Example: <ol style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none"><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word"><font face="UICTFontTextStyleTallBody"><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">let</span> <span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">metatype</span><span style="background-color:rgba(255,255,255,0)">: </span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">SomeClass</span><span style="background-color:rgba(255,255,255,0)">.</span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">Type</span><span style="background-color:rgba(255,255,255,0)"> = SomeClass.</span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">self</span></font></code></li></ol><div><br></div><div>Is there a reason why this isn&#39;t <span style="background-color:rgba(255,255,255,0)">SomeClass.</span>type? Everywhere in the document this is explained as returning the type yet it&#39;s using a postfix self to access the type. </div><div><br></div><div>I propose changing the postfix self to something more obvious like &quot;type&quot;</div><div><br></div><div>Going back to the example:</div><div><ol style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none"><li style="text-indent:0px;border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;list-style-type:none"><code style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;word-wrap:break-word"><font face="UICTFontTextStyleTallBody"><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">let</span> <span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">metatype</span><span style="background-color:rgba(255,255,255,0)">: SomeClass.</span><span style="background-color:rgba(255,255,255,0);border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline">Type</span><span style="background-color:rgba(255,255,255,0)"> = SomeClass.type</span></font></code></li></ol><div><br></div></div><div>Several reasons why I think this is better:</div><div>1. Postfix self is not obvious as an option as you never see a postfix self anywhere else </div><div>2. &quot;self&quot; does not clearly explain that the type is being returned </div><div>3. ObjC programmers are familiar with accessing the class type by sending the &quot;class&quot; method to the class type. In this case it needs to work on structs and enums, so a &quot;type&quot; method would make more sense. </div><div>4. Instances have a dynamicType method. For consistency, classes, structs, etc., should have a type method</div><div><br></div><div>Any other suggestions would be welcome. </div><div><br></div><div>Brandon </div><span></span><br><span>Sent from my iPad</span><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=8CZIdLciSFC-2BO5jF-2FiP8qN7dBFsgCUZ50wdTsolcRPcMHsgQz33SrTbIBqh0dxknVxlPrKM0qDNDweGmZL1cMon3PZ86xs9skTnDn9Mn1zx1MxqQrWOqohYw-2BZuIliB4PP8pQkkyelHQxAWhhF1ffVk7-2F-2FYeJOfDcoz-2BBqTCHovFaF7LhZjwOQBBfBVHeCCYOqT6MJXwWRJr17QyAt9KJtBNrY4R0LnkavP7Rf5ghMc-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
_______________________________________________<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/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>