<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><div id="bloop_customfont" style="margin: 0px;">This one have bothered me for days, since the idea came to my mind.</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">I don't want to be too futuristic so here are my first thoughts.</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">What if Swift 3 would have the ability to merge types and protocols together?</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">Sure we will see generic typealias in Swift 3 but it doesn't allow us merge value types which conforms to specific protocols (if there is a need).</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">protocol SomeProtocol {</div><div id="bloop_customfont" style="margin: 0px;"><span class="Apple-tab-span" style="white-space:pre">        </span></div><div id="bloop_customfont" style="margin: 0px;"><span class="Apple-tab-span" style="white-space:pre">        </span>func boo()</div><div id="bloop_customfont" style="margin: 0px;">}</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">// this use-case can be solved with generic typealias in Swift 3 (at least for classes), but it is not the only one usecase of type merging</div><div id="bloop_customfont" style="margin: 0px;">func foo(mergedInstance: type&lt;UIView, SomeProtocol&gt;) {</div><div id="bloop_customfont" style="margin: 0px;"><span class="Apple-tab-span" style="white-space:pre">        </span></div><div id="bloop_customfont" style="margin: 0px;"><span class="Apple-tab-span" style="white-space:pre">        </span>mergedInstance.removeFromSuperview() // just for the example</div><div id="bloop_customfont" style="margin: 0px;"><span class="Apple-tab-span" style="white-space:pre">        </span>mergedInstance.boo()</div><div id="bloop_customfont" style="margin: 0px;">}</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">extension UIButton: SomeProtocol { /* implemnt boo() */ }</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">let button: SomeProtocol = UIButton() // decouple UIButton first</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">Ok now I want to use one instance as SomeProtocol and UIView.</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">// another possible use-case</div><div id="bloop_customfont" style="margin: 0px;">if let mergedView = button as? type&lt;UIView, SomeProtocol&gt; {</div><div id="bloop_customfont" style="margin: 0px;"><span class="Apple-tab-span" style="white-space:pre">        </span></div><div id="bloop_customfont" style="margin: 0px;"><span class="Apple-tab-span" style="white-space:pre">        </span>mergedView.removeFromSuperview() // just for the example</div><div id="bloop_customfont" style="margin: 0px;"><span class="Apple-tab-span" style="white-space:pre">        </span>mergedView.boo()</div><div id="bloop_customfont" style="margin: 0px;">}</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">More detailed design:</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">- type&lt;&gt; can contain only one value or reference type and n protocols</div><div id="bloop_customfont" style="margin: 0px;">- value or reference type should always be the first type</div><div id="bloop_customfont" style="margin: 0px;">- type&lt;&gt; should always contain at least 2 types (one value or reference type and min. one protocol)</div><div id="bloop_customfont" style="margin: 0px;">- reference types does represent one possible super/base type of the actuall type&nbsp;</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp;* class A {}</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp;* class B: A {}</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp;* class C: B {}</div><div id="bloop_customfont" style="margin: 0px;">&nbsp; &nbsp; &nbsp;* possible types for B and C: type&lt;B, AnyProtocolType, ...&gt; or type&lt;A, AnyProtocolType, ...&gt;</div><div id="bloop_customfont" style="margin: 0px;">- the dynamicType/Self instance passed to type&lt;&gt; conforms to all protocols type&lt;&gt; contains</div><div id="bloop_customfont" style="margin: 0px;"><br></div><div id="bloop_customfont" style="margin: 0px;">If there is more rules one would apply to this idea feel free to discuss them here.</div></div><br><div id="bloop_sign_1462393281052855040" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">--&nbsp;<br>Adrian Zubarev<br>Sent with Airmail</div></div></body></html>