<div dir="ltr">To my knowledge, you can’t do exactly what you’re trying to do, but this is close:<div><br></div><div><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz"><span style="color:#bb2ca2">for</span><span> subclassObject </span><span style="color:#bb2ca2">in</span><span> </span><span style="color:#4f8187">objects</span><span> {</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz"><span>    </span><span style="color:#bb2ca2">switch</span><span> subclassObject.</span><span style="color:#bb2ca2">self</span><span> {</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz;color:rgb(79,129,135)"><span style="color:#000000">    </span><span style="color:#bb2ca2">case</span><span style="color:#000000"> </span><span style="color:#bb2ca2">is</span><span style="color:#000000"> </span><span>Subclass1</span><span style="color:#000000">:</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz"><span>        </span><span style="color:#31595d">doSomethingWith</span><span>(subclassObject </span><span style="color:#bb2ca2">as</span><span>! </span><span style="color:#4f8187">Subclass1</span><span>)</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz;min-height:16px"><span></span><br></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz;color:rgb(79,129,135)"><span style="color:#000000">    </span><span style="color:#bb2ca2">case</span><span style="color:#000000"> </span><span style="color:#bb2ca2">is</span><span style="color:#000000"> </span><span>Subclass2</span><span style="color:#000000">:</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz"><span>        </span><span style="color:#31595d">doSomethingWith</span><span>(subclassObject </span><span style="color:#bb2ca2">as</span><span>! </span><span style="color:#4f8187">Subclass2</span><span>)</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz;min-height:16px"><span></span><br></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz;color:rgb(79,129,135)"><span style="color:#000000">    </span><span style="color:#bb2ca2">case</span><span style="color:#000000"> </span><span style="color:#bb2ca2">is</span><span style="color:#000000"> </span><span>Subclass3</span><span style="color:#000000">:</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz"><span>        </span><span style="color:#31595d">doSomethingWith</span><span>(subclassObject </span><span style="color:#bb2ca2">as</span><span>! </span><span style="color:#4f8187">Subclass3</span><span>)</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz;min-height:16px"><span></span><br></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz;color:rgb(187,44,162)"><span style="color:#000000">    </span><span>default</span><span style="color:#000000">:</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz"><span>        </span><span style="color:#bb2ca2">break</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz"><span>    }</span></p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz">













</p><p style="margin:0px;font-size:12px;line-height:normal;font-family:Inconsolata-dz"><span>}</span></p></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 8, 2016 at 10:11 AM, Nate Birkholz via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This looks like it doesn&#39;t work (swift 2.x), but wanted to be sure it&#39;s not supported:<div>







<p><span>class</span><span> Superclass {}<br></span><span>class</span><span> Subclass1 : </span><span>Superclass</span><span> {}<br></span><span>class</span><span> Subclass2 : </span><span>Superclass</span><span> {}<br></span><span>class</span><span> Subclass3 : </span><span>Superclass</span><span> {}</span></p>
<p><span>let</span><span> sc1 = </span><span>Subclass1</span><span>()<br></span><span>let</span><span> sc2 = </span><span>Subclass2</span><span>()<br></span><span>let</span><span> sc3 = </span><span>Subclass3</span><span>()</span></p>
<p><span>let</span><span> objects : [</span><span>Superclass</span><span>] = [</span><span>sc1</span><span>, </span><span>sc2</span><span>, </span><span>sc3</span><span>]</span></p>
<p><span>for</span><span> subclassObject </span><span>in</span><span> </span><span>objects</span><span> {<br></span><span>    switch</span><span> subclassObject {<br></span><span>    </span><span>case</span><span> </span><span>let</span><span> object = subclassObject </span><span>as</span><span>? Subclass1:<br></span>        doSomethingWith(object)<br><span>    </span><span>case</span><span> </span><span>let</span><span> object = subclassObject </span><span>as</span><span>? Subclass2:<br></span><span>        </span>doSomethingWith(object)<br><span>    </span><span>case</span><span> </span><span>let</span><span> object = subclassObject </span><span>as</span><span>? Subclass3:<br></span><span>        </span>doSomethingWith(object)<br><span>    </span><span>default</span><span>:<br></span><span>        </span><span>return<br></span>    }<br>}</p></div><div><div>This gives an error, expecting a colon (:) after object on every case.</div><div><br></div><div>I wanted to be sure I wasn&#39;t missing something in my syntax (nor some obvious-to-others reason this isn&#39;t supported) before going to swift evolution.</div><span><font color="#888888"><div><br clear="all"><div><br></div>-- <br><div data-smartmail="gmail_signature">Nate Birkholz</div>
</div></font></span></div></div>
<br>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div></div>