<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="">Hi Austin,</div><div class=""><br class=""></div><div class="">let me repeat the example so that clarify my point from this example.</div><div class=""><br class=""></div><div class="">protocol cannot do this:</div><div class=""><br class=""></div><div class=""><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: <font color="#3495af" class="">ProtocolForABC</font></span><span class="">) {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"> print(value.someCommonProperty)</div><div class=""><span class="" style="color: rgb(0, 143, 0);"><br class=""></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 no other cases, but compiler will not 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><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><span class=""><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;"><span class=""><div style="font-family: Helvetica; font-size: 12px;" class="">The compiler will not know your protocol is only conformed to these three classes.</div><div class="">So the else block will not trigger a warning.</div><div class=""><br class=""></div><div class="">- Jiannan</div><div style="font-family: 'Fira Code'; font-size: 11px;" class=""><br class=""></div></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: 'Fira Code';"><br class=""></div><div><blockquote type="cite" class=""><div class="">在 2016年5月16日,18:37,Austin Zheng <<a href="mailto:austinzheng@gmail.com" class="">austinzheng@gmail.com</a>> 写道:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I'm sorry, but I don't understand the point you are trying to make.<div class=""><br class=""></div><div class="">If you pass in a value of type (A | B | C) to a function, what might you want to do with that value?</div><div class=""><br class=""></div><div class="">If you want to do one thing if the value is type A, something else if the value is type B, and something else if the value is type C, then you need to switch or otherwise type check the value at runtime. You can't get around this, no matter whether you use enums, protocols, generics, or union type.</div><div class=""><br class=""></div><div class="">If you want it to do something that A, B, and C all support, use a generic and/or a protocol. In this case limiting the inputs to only those three types is probably a design smell. The whole point of a shared interface is that it only matters that the interface is properly implemented by a type, not what that type is.</div><div class=""><br class=""></div><div class="">If you don't care about doing anything with the value, just make your function generic: func<T>(input: T).</div><div class=""><br class=""></div><div class="">Austin</div><div class=""><br class=""></div></div></div></blockquote></div><br class=""></body></html>