<html><head><meta http-equiv="Content-Type" content="text/html charset=gb2312"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><div class=""><span class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="color: rgb(0, 143, 0);" class=""><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';">Consider this case:</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(4, 51, 255);">class</span><span class=""> A {</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class=""> var someCommonProperty: Int = 0</span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="">}</span></div><div class="" style="margin: 0px; line-height: normal;"><span class=""><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(4, 51, 255);">class</span><span class=""> B {</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class=""> var someCommonProperty: Int = 0</span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="">}</span></div><div class="" style="margin: 0px; line-height: normal;"><span class=""><div class="" style="margin: 0px; line-height: normal;"><span class="" style="color: rgb(4, 51, 255);">class</span><span class=""> C {</span></div><div class="" style="margin: 0px; line-height: normal; min-height: 13px;"><span class=""> var someCommonProperty: Int = 0</span><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="">}</span></div></span></div></span></div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="color: rgb(4, 51, 255);">protocol</span><span class=""> UnionABC {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""> var someCommonProperty: Int</span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="">}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""></span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);"><span class="">extension</span><span class=""> </span><span class="" style="color: rgb(52, 149, 175);">A</span><span class="">: </span><span class="" style="color: rgb(52, 149, 175);">UnionABC</span><span class=""> {}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);"><span class="">extension</span><span class=""> </span><span class="" style="color: rgb(52, 149, 175);">B</span><span class="">: </span><span class="" style="color: rgb(52, 149, 175);">UnionABC</span><span class=""> {}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);"><span class="">extension</span><span class=""> </span><span class="" style="color: rgb(52, 149, 175);">C</span><span class="">: </span><span class="" style="color: rgb(52, 149, 175);">UnionABC</span><span class=""> {}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);"><span class=""><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);"><span style="color: rgb(0, 143, 0);" class="">===================== If we using protocol</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""></span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""></span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="color: rgb(4, 51, 255);">func</span><span class=""> input(value: </span><span class="" style="color: rgb(52, 149, 175);">UnionABC</span><span class="">) {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""><div class="" style="margin: 0px; line-height: normal;"> print(value.someCommonProperty) <span style="color: rgb(0, 143, 0);" class="">// Compiler will know their common properties automatically.</span></div></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> </span><span class="" style="color: rgb(4, 51, 255);">if</span><span class=""> value </span><span class="" style="color: rgb(4, 51, 255);">is</span><span class=""> </span><span class="" style="color: rgb(52, 149, 175);">A</span><span class=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""> </span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> } </span><span class="" style="color: rgb(4, 51, 255);">else</span><span class=""> </span><span class="" style="color: rgb(4, 51, 255);">if</span><span class=""> value </span><span class="" style="color: rgb(4, 51, 255);">is</span><span class=""> </span><span class="" style="color: rgb(52, 149, 175);">B</span><span class=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""> </span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> } </span><span class="" style="color: rgb(4, 51, 255);">else</span><span class=""> </span><span class="" style="color: rgb(4, 51, 255);">if</span><span class=""> value </span><span class="" style="color: rgb(4, 51, 255);">is</span><span class=""> </span><span class="" style="color: rgb(52, 149, 175);">C</span><span class=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""> </span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> } </span><span class="" style="color: rgb(4, 51, 255);">else</span><span class=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(0, 143, 0);"><span class=""> </span><span class="">// There are other cases? Compiler doesn't know</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> }</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="">}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""></span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="color: rgb(4, 51, 255);">let</span><span class=""> a = </span><span class="" style="color: rgb(52, 149, 175);">A</span><span class="">()</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><span class="">input</span><span class="">(</span><span class="">a</span><span class="">)</span></div></span></div></div></div></blockquote></div></div></div><br class=""></div><div class=""><span style="color: rgb(0, 143, 0); font-family: 'Fira Code'; font-size: 11px;" class="">===================== If we using union</span></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""></span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="color: rgb(4, 51, 255);">func</span><span class=""> input(value: </span><span class="" style="color: rgb(52, 149, 175);">(A | B | C)</span><span class="">) {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"> print(value.someCommonProperty) <span style="color: rgb(0, 143, 0);" class="">// Compiler will know their common properties automatically.</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> </span><span class="" style="color: rgb(4, 51, 255);">if</span><span class=""> value </span><span class="" style="color: rgb(4, 51, 255);">is</span><span class=""> </span><span class="" style="color: rgb(52, 149, 175);">A</span><span class=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""> </span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> } </span><span class="" style="color: rgb(4, 51, 255);">else</span><span class=""> </span><span class="" style="color: rgb(4, 51, 255);">if</span><span class=""> value </span><span class="" style="color: rgb(4, 51, 255);">is</span><span class=""> </span><span class="" style="color: rgb(52, 149, 175);">B</span><span class=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""> </span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> } </span><span class="" style="color: rgb(4, 51, 255);">else</span><span class=""> </span><span class="" style="color: rgb(4, 51, 255);">if</span><span class=""> value </span><span class="" style="color: rgb(4, 51, 255);">is</span><span class=""> </span><span class="" style="color: rgb(52, 149, 175);">C</span><span class=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""> </span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> } </span><span class="" style="color: rgb(4, 51, 255);">else</span><span class=""> {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(0, 143, 0);"><span class=""> </span><span class="">// There no other cases, so the compiler trigger a warning.</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""> }</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="">}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class=""></span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="color: rgb(4, 51, 255);">let</span><span class=""> a = </span><span class="" style="color: rgb(52, 149, 175);">A</span><span class="">()</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><span class="">input</span><span class="">(</span><span class="">a</span><span class="">)</span></div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><span class=""><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><div dir="ltr" class=""><div class="" style="color: rgb(0, 0, 0);"><font color="#008f00" class="">=====================</font></div><div class="" style="color: rgb(0, 0, 0);"><font color="#008f00" class=""><br class=""></font></div><div class="" style="color: rgb(0, 0, 0);"><div class="" style="font-family: Helvetica; font-size: 12px;">If using generic enum,</div><div class="" style="font-family: Helvetica; font-size: 12px;">the compiler doesn’t know the type relation between generic union with original type.</div><div class="" style="font-family: Helvetica; font-size: 12px;">class A and UnionOf3<A,B,C> are totally two different types, has no relationship.</div><div class="" style="font-family: Helvetica; font-size: 12px;">But class A and (A | B | C) keeps a relationship.</div><div class="" style="font-family: Helvetica; font-size: 12px;"><br class=""></div></div><div class="" style="color: rgb(0, 0, 0);"><font color="#008f00" class="">If using union, these two cases will be allowed:</font></div><div class="" style="color: rgb(0, 0, 0);"><font color="#008f00" class=""><br class=""></font></div><div class="" style="color: rgb(0, 0, 0);"><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> a = </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">A</span><span class="" style="font-variant-ligatures: no-common-ligatures;">()</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="" style="color: rgb(4, 51, 255);">let</span> union: (A|B|C) = </span><span class="" style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;">a </span><span class="" style="color: rgb(0, 143, 0);">// Automatically wrap.</span></div><div class="" style="font-family: Helvetica; font-size: 12px; margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;">a == union // Can be compared, Yes</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="font-family: Helvetica; font-size: 12px; margin: 0px; line-height: normal;">sub-typing: </div><div class=""><br class=""></div><div class=""><div class="" style="font-family: Helvetica; font-size: 12px;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">var</span> fn0: <span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">A</span>-><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">Void</span> = {<span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">print</span>(v0)}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="" style="color: rgb(4, 51, 255);">var</span> fn1<span class="" style="font-variant-ligatures: no-common-ligatures;">: <font color="#3495af" class="">(A|B)</font></span>-><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">Void</span> = {<span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">print</span>(v0)}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><br class=""></div></div><div class="" style="font-family: Helvetica; font-size: 12px; margin: 0px; line-height: normal;"><span class="" style="font-family: 'Fira Code'; font-size: 11px; font-variant-ligatures: no-common-ligatures;">fn0 = fn1 </span><span class="" style="font-family: 'Fira Code'; font-size: 11px; color: rgb(0, 143, 0);">// Original Type and Union Type has a sub-typing relationship, OK</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="" style="color: rgb(4, 51, 255);">var</span> fn2: <span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">(A|B|C)</span>-><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">Void</span> = {<span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">print</span>($0)}</span></div><div class="" style="margin: 0px; line-height: normal;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;">fn0 = fn2 <span class="" style="color: rgb(0, 143, 0);">// OK</span></div><div class="" style="font-family: Helvetica; font-size: 12px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="font-variant-ligatures: no-common-ligatures;">fn1 = fn2 <span class="" style="color: rgb(0, 143, 0);">// OK</span></span></div></span></div></div></span></div></div></div><div class=""><div dir="ltr" class=""><br class=""></div></div></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">在 2016年5月16日,18:17,Austin Zheng <<a href="mailto:austinzheng@gmail.com" class="">austinzheng@gmail.com</a>> 写道:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">This doesn't explain how I can use 'value' once an A() is passed into the function:<div class=""><br class=""><div class=""><div style="margin: 0px; font-size: 11px; font-family: 'Fira Code';" class=""><span style="color:rgb(4,51,255)" class="">func</span> input(value: (<span style="color:rgb(52,149,175)" class="">A</span> | B | C)) {</div><div style="margin: 0px; font-size: 11px; font-family: 'Fira Code'; min-height: 13px;" class=""> <br class=""></div><div style="margin: 0px; font-size: 11px; font-family: 'Fira Code';" class="">}</div></div><div class=""><br class=""></div><div class="">If A, B, and C are not related via protocol or class inheritance, then there is almost nothing you can do with value. Otherwise you still need to test against the concrete type using a case statement or a if-else ladder.</div><div class=""><br class=""></div><div class="">The other 'gain' is being able to call 'input(A())', rather than 'input(.caseA(A()))'. I agree that the first form is prettier than the second one. I also think you could make the language pervasively prettier and more expressive by allowing for all sorts of implicit conversions. At some point clarity at the point of use beats conciseness, especially when code within a complex codebase needs to be maintained.</div><div class=""><br class=""></div><div class="">I understand that this is largely a matter of style - different people value different things, and that's wonderful. I welcome a formal proposal submitted to the swift-evolution process, and if one appears I'm happy to consider it in more detail and argue for or against it based on that.</div><div class=""><br class=""></div><div class="">Austin</div><div class=""><br class=""></div><div class=""><br class=""></div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, May 15, 2016 at 3:34 AM, Cao Jiannan <span dir="ltr" class=""><<a href="mailto:frogcjn@163.com" target="_blank" class="">frogcjn@163.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">for example, there is a method input union of 3 types: A, B, C,<div class=""><br class=""></div><div class="">This is the three class.</div><div class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">class</span><span class=""> A {}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">class</span><span class=""> B {}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">class</span><span class=""> C {}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""><br class=""></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""><div style="font-family:Helvetica;font-size:12px" class="">This is how it implemented under Swift 2:</div></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">enum</span><span class=""> UnionABC {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""> </span><span style="color:#0433ff" class="">case</span><span class=""> classA(</span><span style="color:#3495af" class="">A</span><span class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""> </span><span style="color:#0433ff" class="">case</span><span class=""> classB(</span><span style="color:#3495af" class="">B</span><span class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""> </span><span style="color:#0433ff" class="">case</span><span class=""> classC(</span><span style="color:#3495af" class="">C</span><span class="">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">func</span><span class=""> input(value: </span><span style="color:#3495af" class="">UnionABC</span><span class="">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class=""> </span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">let</span><span class=""> a = </span><span style="color:#3495af" class="">A</span><span class="">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">let</span><span class=""> b = </span><span style="color:#3495af" class="">B</span><span class="">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">let</span><span class=""> c = </span><span style="color:#3495af" class="">C</span><span class="">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';color:rgb(52,149,175)" class=""><span class="">input</span><span style="" class="">(</span><span class="">UnionABC</span><span style="" class="">.</span><span class="">classA</span><span style="" class="">(</span><span class="">a</span><span style="" class="">))</span></div><div class=""><span style="" class=""><br class=""></span></div><div class=""><span style="" class=""><br class=""></span></div><div class=""><span style="" class="">It needs announce all the cases and name each cases and cannot use class names as their case names.</span></div><div class=""><span style="" class=""><br class=""></span></div><div class=""><span style="" class="">what about using union? It is more easy and rational.</span></div><div class=""><span style="" class=""><br class=""></span></div><div class=""><span style="" class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">func</span><span class=""> input(value: (</span><span style="color:#3495af" class="">A</span><span class=""> | B | C)) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class=""> </span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">let</span><span class=""> a= </span><span style="color:#3495af" class="">A</span><span class="">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';color:rgb(52,149,175)" class=""><span class="">input</span><span style="" class="">(</span><span class="">a</span><span style="" class="">)</span></div><div class=""><span style="" class=""><br class=""></span></div></span></div><div class=""><span style="" class="">Or you can implement it with protocol and extension, but compiler will not know how many cases it should have.</span></div><div class=""><br class=""></div><div class=""><span style="" class=""><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">protocol</span><span class=""> UnionABC {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class=""> </span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';color:rgb(4,51,255)" class=""><span class="">extension</span><span style="" class=""> </span><span style="color:#3495af" class="">A</span><span style="" class="">: </span><span style="color:#3495af" class="">UnionABC</span><span style="" class=""> {}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';color:rgb(4,51,255)" class=""><span class="">extension</span><span style="" class=""> </span><span style="color:#3495af" class="">B</span><span style="" class="">: </span><span style="color:#3495af" class="">UnionABC</span><span style="" class=""> {}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';color:rgb(4,51,255)" class=""><span class="">extension</span><span style="" class=""> </span><span style="color:#3495af" class="">C</span><span style="" class="">: </span><span style="color:#3495af" class="">UnionABC</span><span style="" class=""> {}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">func</span><span class=""> input(value: </span><span style="color:#3495af" class="">UnionABC</span><span class="">) {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""> </span><span style="color:#0433ff" class="">if</span><span class=""> value </span><span style="color:#0433ff" class="">is</span><span class=""> </span><span style="color:#3495af" class="">A</span><span class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class=""> </span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""> } </span><span style="color:#0433ff" class="">else</span><span class=""> </span><span style="color:#0433ff" class="">if</span><span class=""> value </span><span style="color:#0433ff" class="">is</span><span class=""> </span><span style="color:#3495af" class="">B</span><span class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class=""> </span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""> } </span><span style="color:#0433ff" class="">else</span><span class=""> </span><span style="color:#0433ff" class="">if</span><span class=""> value </span><span style="color:#0433ff" class="">is</span><span class=""> </span><span style="color:#3495af" class="">C</span><span class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class=""> </span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""> } </span><span style="color:#0433ff" class="">else</span><span class=""> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';color:rgb(0,143,0)" class=""><span style="" class=""> </span><span class="">// There are other cases? Compiler doesn't know</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class=""> }</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span class="">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';min-height:13px" class=""><span class=""></span><br class=""></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code'" class=""><span style="color:#0433ff" class="">let</span><span class=""> a = </span><span style="color:#3495af" class="">A</span><span class="">()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:'Fira Code';color:rgb(52,149,175)" class=""><span class="">input</span><span style="" class="">(</span><span class="">a</span><span style="" class="">)</span></div><div class=""><span style="" class=""><br class=""></span></div><div class=""><span style="" class=""><br class=""></span></div></span></div><div class=""><br class=""><blockquote type="cite" class=""><div class="">下面是被转发的邮件:</div><br class=""><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">发件人: </b></span><span style="font-family:-webkit-system-font,Helvetica Neue,Helvetica,sans-serif" class=""><a href="mailto:frogcjn@163.com" target="_blank" class="">frogcjn@163.com</a><br class=""></span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">主题: </b></span><span style="font-family:-webkit-system-font,Helvetica Neue,Helvetica,sans-serif" class=""><b class="">回复: [swift-evolution] Union instead of Optional</b><br class=""></span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">日期: </b></span><span style="font-family:-webkit-system-font,Helvetica Neue,Helvetica,sans-serif" class="">2016年5月15日 GMT+8 18:00:55<br class=""></span></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px" class=""><span style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;" class=""><b class="">收件人: </b></span><span style="font-family:-webkit-system-font,Helvetica Neue,Helvetica,sans-serif" class="">Austin Zheng <<a href="mailto:austinzheng@gmail.com" target="_blank" class="">austinzheng@gmail.com</a>><br class=""></span></div><br class=""><div class=""><div dir="auto" class=""><span class=""><div class=""><br class="">Enum and Union are two things.</div><div class=""><br class=""></div><div class="">If you use Enum to implement Union, you should announce it with case name.</div><div class=""><br class=""></div><div class="">Another issue using enum instead of union is that, union can combine types as many as possible, you just write ( A | B | C ... | Z), but for enum, you should carefully announce it for each case. </div><div class=""><br class="">在 2016年5月15日,15:22,Austin Zheng <<a href="mailto:austinzheng@gmail.com" target="_blank" class="">austinzheng@gmail.com</a>> 写道:<br class=""><br class=""></div></span><blockquote type="cite" class=""><div class=""><span class="">In addition, not everything in Swift can be modeled in terms of inheritance relationships.<div class=""><br class=""></div></span><div class=""><span class="">I'm a little curious as to why union types keep on coming up, when enums can do everything they can and much more (methods, constraints on generic types, conformance to protocols).<br class=""><div class=""><br class=""></div><div class="">Austin</div></span><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" class=""><div 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" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><span class=""><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important" class="">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" class="">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br class=""></div></div>
</div></blockquote></div></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>