<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 style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);" class=""><div class=""><div class="">This is the example implemented with generic and enum.</div></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> UnionOf3 <T,U,V>{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> type0(</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">T</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> type1(</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">U</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> type2(</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">V</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> input(value: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">UnionOf3</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">B</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">C</span><span style="font-variant-ligatures: no-common-ligatures" class="">>) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures" class=""> value {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">type0</span><span style="font-variant-ligatures: no-common-ligatures" class="">(a):</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(a)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">type1</span><span style="font-variant-ligatures: no-common-ligatures" class="">(b):</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(b)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">type2</span><span style="font-variant-ligatures: no-common-ligatures" class="">(c):</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">(c)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> a = </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">input</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">UnionOf3</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures" class="">type0</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures" class="">a</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">))</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><div>For each different number N of types to get union, you should announce UnionOfN for each.</div></span></div><div>it is more complicated then the union solution. </div><div><br class=""></div><div><div class=""><div class=""><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; color: rgb(4, 51, 255);">func</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> input(value: (</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><span style="color: rgb(52, 149, 175);" class="">B</span> | <span style="color: rgb(52, 149, 175);" class="">C</span>)) {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> value {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> a <font color="#0433ff" class="">as </font></span><span style="color: rgb(52, 149, 175);" class="">A</span>:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(a)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures;" class="">b </span><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#0433ff" class="">as </font><font color="#3495af" class="">B</font></span>:</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(b)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> .</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">type2</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(c):</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(c)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> }</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></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; 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; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><span class="" style="font-variant-ligatures: no-common-ligatures;">input</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">a</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div><br class=""></div><div class="">And the most bad thing is,</div><div class="">compiler doesn’t know the type relation between generic union with original type,</div><div class=""> for example, the type relation between A and A | B and A | B | C.</div><div class=""><br class=""></div><div class="">compare:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> UnionOf3 <T,U,V>{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> type0(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">T</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> type1(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">U</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">case</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> type2(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">V</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div></div><div class=""><br class=""></div></span></div></div></span></div></div></div><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; 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; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span style="color: rgb(4, 51, 255);" class="">let</span> union: UnionOf3<A,B,C> = </span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">UnionOf3</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">type0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">a</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="color: rgb(0, 143, 0);" class="">// You should wrap by yourself.</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 style="font-variant-ligatures: no-common-ligatures;" class="">a == union // probably the compiler will refuse to compare.</span></div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; line-height: normal;">sub-typing: </div><div class="" style="margin: 0px; line-height: normal;"><br class=""></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;"><div style="font-family: Helvetica; font-size: 12px;" class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0433ff" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> fn0: </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">A</span><span style="font-variant-ligatures: no-common-ligatures" class="">-></span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = {</span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">print</span><span style="font-variant-ligatures: no-common-ligatures" class="">($0)}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="color: rgb(4, 51, 255);" class="">var</span> fn1<span style="font-variant-ligatures: no-common-ligatures;" class="">: <font color="#3495af" class="">UnionOf2<A,B></font></span><span style="font-variant-ligatures: no-common-ligatures;" class="">-></span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Void</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> = {</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">($0)}</span></div></div></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><br class=""></div></div><div class="" style="margin: 0px; line-height: normal;"><span style="font-family: 'Fira Code'; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">fn0 = fn1 </span><span style="font-family: 'Fira Code'; font-size: 11px; color: rgb(0, 143, 0);" class="">// This should be allowed. But will be rejected </span><font color="#008f00" face="Fira Code" class=""><span style="font-size: 11px;" class="">since using enum.</span></font></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class=""><span style="color: rgb(4, 51, 255);" class="">var</span> fn2: <span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">UnionOf3<A,B,C></span>-><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Void</span> = {<span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">print</span>($0)}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';">fn0 = fn2 <span style="color: rgb(0, 143, 0);" class="">// This should be allowed. </span><span style="color: rgb(0, 143, 0);" class="">But will be rejected </span><font color="#008f00" face="Fira Code" class="">since using enum.</font></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class="">fn1 = fn2 <span style="color: rgb(0, 143, 0);" class="">// This should be allowed. </span></span><span style="color: rgb(0, 143, 0);" class="">But will be rejected </span><font color="#008f00" face="Fira Code" class="">since using enum.</font></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class=""><span style="color: rgb(0, 143, 0);" class=""><br class=""></span></span></div><div class="" style="margin: 0px; line-height: normal;"><div class=""><font face="Fira Code" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div class=""><font face="Fira Code" class=""><span style="font-size: 11px;" class="">---------------------------------------------------------------------------</span></font></div><div class=""><font face="Fira Code" class=""><span style="font-size: 11px;" class=""><br class=""></span></font></div><div class=""><font face="Fira Code" class=""><span style="font-size: 11px;" class="">If using union, this problem can be solved easily.</span></font></div><div class=""><br class=""></div></div></span></div></div><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; 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; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="font-variant-ligatures: no-common-ligatures;"><span style="color: rgb(4, 51, 255);" class="">let</span> union: (A|B|C) = </span><span style="color: rgb(52, 149, 175); font-variant-ligatures: no-common-ligatures;" class="">a </span><span style="color: rgb(0, 143, 0);" class="">// Automatically wrap.</span></div><div class="" style="margin: 0px; line-height: normal;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class="">a == union // Yes</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class=""><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 style="font-family: Helvetica; font-size: 12px;" class=""><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 style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);" class="">var</span> fn0: <span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">A</span>-><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Void</span> = {<span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">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 style="color: rgb(4, 51, 255);" class="">var</span> fn1<span style="font-variant-ligatures: no-common-ligatures;" class="">: <font color="#3495af" class="">(A|B)</font></span>-><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Void</span> = {<span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">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 style="font-family: 'Fira Code'; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class="">fn0 = fn1 </span><span style="font-family: 'Fira Code'; font-size: 11px; color: rgb(0, 143, 0);" class="">// OK</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span style="font-variant-ligatures: no-common-ligatures;" class=""><span style="color: rgb(4, 51, 255);" class="">var</span> fn2: <span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">(A|B|C)</span>-><span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">Void</span> = {<span style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);" class="">print</span>($0)}</span></div><div class="" style="margin: 0px; line-height: normal;"><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;">fn0 = fn2 <span style="color: rgb(0, 143, 0);" class="">// OK</span></div><div style="font-family: Helvetica; font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class="">fn1 = fn2 <span style="color: rgb(0, 143, 0);" class="">// OK</span></span></div></span></div></div></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><blockquote type="cite" class=""><div class="">下面是被转发的邮件:</div><br class="Apple-interchange-newline"><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; color:rgba(0, 0, 0, 1.0);" class=""><b class="">发件人: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Cao Jiannan via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</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; color:rgba(0, 0, 0, 1.0);" class=""><b class="">主题: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class=""><b class="">[swift-evolution] Fwd: 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; color:rgba(0, 0, 0, 1.0);" class=""><b class="">日期: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">2016年5月15日 GMT+8 18:34:44<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; color:rgba(0, 0, 0, 1.0);" class=""><b class="">收件人: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</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; color:rgba(0, 0, 0, 1.0);" class=""><b class="">回复-收件人: </b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Cao Jiannan <<a href="mailto:frogcjn@163.com" class="">frogcjn@163.com</a>><br class=""></span></div><br class=""><div class=""><span 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-stroke-width: 0px; float: none; display: inline !important;" class="">for example, there is a method input union of 3 types: A, B, C,</span><div class="" 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-stroke-width: 0px;"><br class=""></div><div class="" 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-stroke-width: 0px;">This is the three class.</div><div class="" 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-stroke-width: 0px;"><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="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">class</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>A {}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; color: rgb(4, 51, 255);">class</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>B {}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; color: rgb(4, 51, 255);">class</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>C {}</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;"><br class=""></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;"><div class="" style="font-family: Helvetica; font-size: 12px;">This is how it implemented under Swift 2:</div></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; color: rgb(4, 51, 255);">enum</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>UnionABC {</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="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>classA(</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; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class="" style="font-variant-ligatures: no-common-ligatures;"> <span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>classB(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">B</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</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="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">case</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>classC(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">C</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</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></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; color: rgb(4, 51, 255);">func</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>input(value:<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">UnionABC</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><br class="webkit-block-placeholder"></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></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; color: rgb(4, 51, 255);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>a =<span class="Apple-converted-space"> </span></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; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><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;"><span class="Apple-converted-space"> </span>b =<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">B</span><span class="" style="font-variant-ligatures: no-common-ligatures;">()</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; color: rgb(4, 51, 255);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>c =<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">C</span><span class="" style="font-variant-ligatures: no-common-ligatures;">()</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><span class="" style="font-variant-ligatures: no-common-ligatures;">input</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">UnionABC</span><span class="" style="font-variant-ligatures: no-common-ligatures;">.</span><span class="" style="font-variant-ligatures: no-common-ligatures;">classA</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">a</span><span class="" style="font-variant-ligatures: no-common-ligatures;">))</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;">It needs announce all the cases and name each cases and cannot use class names as their case names.</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;">what about using union? It is more easy and rational.</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><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="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">func</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>input(value: (</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 class="Apple-converted-space"> </span>| B | C)) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><br class="webkit-block-placeholder"></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></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; color: rgb(4, 51, 255);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>a=<span class="Apple-converted-space"> </span></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; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><span class="" style="font-variant-ligatures: no-common-ligatures;">input</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">a</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;">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 class="" style="font-variant-ligatures: no-common-ligatures;"><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; color: rgb(4, 51, 255);">protocol</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>UnionABC {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><br class="webkit-block-placeholder"></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></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></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="" style="font-variant-ligatures: no-common-ligatures;">extension</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></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 class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">UnionABC</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>{}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;">extension</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">B</span><span class="" style="font-variant-ligatures: no-common-ligatures;">:<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">UnionABC</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>{}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(4, 51, 255);"><span class="" style="font-variant-ligatures: no-common-ligatures;">extension</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">C</span><span class="" style="font-variant-ligatures: no-common-ligatures;">:<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">UnionABC</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>{}</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; color: rgb(4, 51, 255);">func</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>input(value:<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">UnionABC</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) {</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="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">if</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>value<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">is</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></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 class="Apple-converted-space"> </span>{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><br class="webkit-block-placeholder"></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="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">else</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">if</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>value<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">is</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">B</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><br class="webkit-block-placeholder"></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="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">else</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">if</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>value<span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">is</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 149, 175);">C</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>{</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;" class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"> </span><br class="webkit-block-placeholder"></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="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(4, 51, 255);">else</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(0, 143, 0);"><span class="" style="font-variant-ligatures: no-common-ligatures;"> <span class="Apple-converted-space"> </span></span><span class="" style="font-variant-ligatures: no-common-ligatures;">// 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="" style="font-variant-ligatures: no-common-ligatures;"> }</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></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code'; min-height: 13px;"><span class="" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></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; color: rgb(4, 51, 255);">let</span><span class="" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>a =<span class="Apple-converted-space"> </span></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; font-size: 11px; line-height: normal; font-family: 'Fira Code'; color: rgb(52, 149, 175);"><span class="" style="font-variant-ligatures: no-common-ligatures;">input</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures;">a</span><span class="" style="font-variant-ligatures: no-common-ligatures;">)</span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div></span></div><div class=""><br class=""><blockquote type="cite" class=""><div class="">下面是被转发的邮件:</div><br class="Apple-interchange-newline"><div class="" style="margin: 0px;"><span class="" style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;"><b class="">发件人:<span class="Apple-converted-space"> </span></b></span><span class="" style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;"><a href="mailto:frogcjn@163.com" class="">frogcjn@163.com</a><br class=""></span></div><div class="" style="margin: 0px;"><span class="" style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;"><b class="">主题:<span class="Apple-converted-space"> </span></b></span><span class="" style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;"><b class="">回复: [swift-evolution] Union instead of Optional</b><br class=""></span></div><div class="" style="margin: 0px;"><span class="" style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;"><b class="">日期:<span class="Apple-converted-space"> </span></b></span><span class="" style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;">2016年5月15日 GMT+8 18:00:55<br class=""></span></div><div class="" style="margin: 0px;"><span class="" style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;"><b class="">收件人:<span class="Apple-converted-space"> </span></b></span><span class="" style="font-family: -webkit-system-font, 'Helvetica Neue', Helvetica, sans-serif;">Austin Zheng <<a href="mailto:austinzheng@gmail.com" class="">austinzheng@gmail.com</a>><br class=""></span></div><br class=""><div class=""><div dir="auto" 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" class="">austinzheng@gmail.com</a>> 写道:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">In addition, not everything in Swift can be modeled in terms of inheritance relationships.<div class=""><br class=""></div><div 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><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="" 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-stroke-width: 0px;"><blockquote type="cite" class=""><div class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class="" 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-stroke-width: 0px;"><span class="" 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-stroke-width: 0px; float: none; display: inline !important;">_______________________________________________</span><br class="" 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-stroke-width: 0px;"><span class="" 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-stroke-width: 0px; float: none; display: inline !important;">swift-evolution mailing list</span><br class="" 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-stroke-width: 0px;"><a href="mailto:swift-evolution@swift.org" class="" 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-stroke-width: 0px;">swift-evolution@swift.org</a><br class="" 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-stroke-width: 0px;"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="" 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-stroke-width: 0px;">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></div></blockquote></div></div></blockquote></div><br class=""></div><span 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-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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; 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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; 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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; 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-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; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; 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-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>