<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><style type="text/css">body { background: rgba(255, 255, 255, 255); }</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi everyone,<div class=""><br class=""></div><div class="">This is my first message on the mailing list and I hope I'll do everything right :)</div><div class="">I've been through the mailing-list archive and I didn't see anything close to this proposal so I hope I didn't miss anything.</div><div class=""><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';" class=""><span style="font-size: 25px;" class="">Introduction</span></h2></div><div class="">Sometimes, there are several ways to represent the same thing. For instance NSURL and NSURLComponents are both used to deal with URLs, but according to the API you want to use you must have to make manual conversions from one type to another. My proposal is to add a built-in bridge feature into the Swift language to remove a lot of boilerplate code and increase readability.</div><div style="font-size: 14px;" class=""><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';" class="">Motivation</h2></div><div style="font-size: 14px;" class=""><b class="">1. It's a really convenient pattern </b></div><div style="font-size: 14px;" class=""><b class=""><br class=""></b></div><div class="">Swift has several great solutions for types. Structs, Enums, and Protocols can do as much as Classes. You can define properties, methods, subscripts, you can extend them, etc.. This allowed developers to use some types where they weren't expected. For instance we can use an enum <span style="color: rgb(61, 114, 120); font-family: Menlo;" class="">AppColors</span> to define all colors used by an app, and as an enum can have properties, we can add a <font face="Menlo" class=""><font color="#ff2f92" class="">var</font><b class=""> </b><font color="#424242" class="">color:</font><b class=""> </b><font color="#eb7100" class="">UIColor</font></font> on it to generate the associate <font color="#eb7100" face="Menlo" class="">UIColor</font> (or <font color="#eb7100" face="Menlo" class="">NSColor</font>)</div><div class=""><br class=""></div><div class="">Its really convenient but wherever we want to use this color, we need to call the <font color="#424242" face="Menlo" class="">.color</font> property :</div><div class=""><font face="Menlo" class=""><font color="#d68945" class="">myLabel</font><font color="#424242" class="">.textColor = </font></font><span style="color: rgb(61, 114, 120); font-family: Menlo;" class="">AppColors</span><font face="Menlo" class=""><font color="#424242" class="">.</font><font color="#59aba0" class="">PrimaryLabelTextColor</font><font color="#424242" class="">.color</font></font></div><div class=""><br class=""></div><div class="">We can also have a protocol <font color="#eb7100" face="Menlo" class="">ColorConvertible</font> defined like this to simplify things :</div><div class=""><font face="Menlo" class=""><font color="#ff2f92" class="">protocol</font><b class=""> </b><font color="#eb7100" class="">ColorConvertible</font><b class=""> </b><font color="#424242" class="">{</font></font></div><div class=""><font face="Menlo" class=""><b class=""> </b><font color="#ff2f92" class="">var</font><b class=""> </b><font color="#424242" class="">color:</font><b class=""> </b><font color="#eb7100" class="">UIColor</font><b class=""> </b><font color="#424242" class="">{ get }</font></font></div><div class=""><font color="#424242" face="Menlo" class="">}</font></div><div class=""><span style="font-family: Menlo;" class=""><br class=""></span></div><div class="">Let's take a more concrete example with the open source library Alamofire (<a href="https://github.com/Alamofire/Alamofire" class="">https://github.com/Alamofire/Alamofire</a>).</div><div class="">Alamofire makes an extensive usage of this pattern to convert different types into a <font face="Menlo" class=""><b class="">"</b><font color="#eb7100" class="">NSURL</font><b class="">-compatible" String</b></font> or a <font color="#eb7100" face="Menlo" class="">NSURLRequest</font> object.</div><div class=""><br class=""></div><div class="">Then the Alamofire API use only those <font color="#eb7100" face="Menlo" class="">URLStringConvertible</font> and <font color="#eb7100" face="Menlo" class="">URLRequestConvertible</font> protocols as method inputs.</div><div class=""><br class=""></div><div class="">It's great because at the right moment where you use the Alamofire API, no matter if you currently use a <font color="#eb7100" face="Menlo" class="">NSURL</font> or a <font color="#eb7100" face="Menlo" class="">NSURLComponent</font>, you can pass both as argument to the Alamofire function.</div><div class=""><br class=""></div><div class="">Moreover, you may want to use a custom type to build your URLs and validate them. This allows you to add some safety because you can use strong-typed enums as path components instead of error-prone strings.</div><div class="">And here is where this pattern is convenient : you can make your custom type (which could be a class, a struct or an enum) conforming to <font color="#eb7100" face="Menlo" class="">URLStringConvertible</font><span style="font-family: Menlo;" class=""> </span>and use it directly as Alamofire API functions input.</div><div class=""><br class=""></div><div class="">But this is sadly limited for Alamofire API. What about all other frameworks which only take <font color="#eb7100" face="Menlo" class="">NSURL</font><b class=""> </b>as input ?</div><div class=""><br class=""></div><div class="">Using protocols for this is counterintuitive :</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>– protocols are especially thought to don't have to deal with a particular type right ? But what we do here ? We use it only to convert the receiver into the desired type. After the conversion, the original receiver is not even used anymore because we can do nothing with it except convert it.</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>– we already can see different way to write these conversions, : </div><div class=""><font class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>- </font><font color="#ff2f92" face="Menlo" class="">var</font><font color="#424242" face="Menlo" class=""> URLString: </font><font color="#3d7278" face="Menlo" class="">String</font><font color="#424242" face="Menlo" class=""> { </font><font color="#ff2f92" face="Menlo" class="">get</font><font color="#424242" face="Menlo" class=""> } </font> arbitrary var name pattern</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>- <font color="#ff2f92" face="Menlo" class="">var</font><font color="#424242" face="Menlo" class=""> integerValue: </font><font color="#3d7278" face="Menlo" class="">Int</font><font color="#424242" face="Menlo" class=""> { </font><font color="#ff2f92" face="Menlo" class="">get</font><font color="#424242" face="Menlo" class=""> }</font> _Value var name pattern (like in <font color="#eb7100" face="Menlo" class="">NSNumber</font>)</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">                </span>- <font color="#ff2f92" face="Menlo" class="">func</font><font color="#424242" face="Menlo" class=""> toColor() -> </font><font color="#eb7100" face="Menlo" class="">UIColor</font><font face="Menlo" class=""><b class=""> </b></font>to_() func name pattern </div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>– everytime we want to have a type conversion we need te create the associated protocol but it won't be compatible with third party libraries unless by manually write forwarding methods...</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div class=""><b class=""><span style="font-size: 14px;" class="">2. Swift language already makes convenient bridges between some Obj-C types and theirs Swift counterparts</span></b></div><div style="font-size: 14px;" class=""><b class=""><br class=""></b></div><div class="">I didn't take the time to see how it's currently implemented right now, but we already have bridging. For instance this code is valid without doing anything : </div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><font color="#ff2f92" face="Menlo" class="">func</font><font color="#424242" face="Menlo" class=""> doSomethingWithNumber(number: </font><font color="#eb7100" face="Menlo" class="">NSNumber</font><font color="#424242" face="Menlo" class="">) {</font></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> //...</font></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class="">}</font></div><div style="margin: 0px; line-height: normal; min-height: 14px;" class=""><font color="#424242" face="Menlo" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><font color="#ff2f92" class="">let</font><font color="#424242" class=""> integer: </font><font color="#3d7278" class="">Int</font><font color="#424242" class=""> = 42</font></font></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class="">doSomethingWithNumber(integer)</font></div><div style="margin: 0px; font-size: 14px; line-height: normal; font-family: Inconsolata; color: rgb(66, 66, 66);" class=""><b class=""> </b></div></div></div><div class=""><h2 style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';" class="">Proposed solution</h2></div><div class="">The cleanest way I see to add this feature is by having a new <span style="color: rgb(255, 47, 146); font-family: Menlo;" class="">bridge</span> keyword. A bridge could be implemented either into the type implementation scope or in an extension. Bridges can also be a protocol requirement and even have a default implementation thanks to protocol extensions. In fact, <span style="color: rgb(255, 47, 146); font-family: Menlo;" class="">bridge</span> keyword can be used in same places than the <span style="color: rgb(255, 47, 146); font-family: Menlo;" class="">subscript</span> keyword.</div><div class=""><br class=""></div><div class="">Here is what it could look like for the above NSURL example (note how the bridge could return an optional if needed) :</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(255, 47, 146);" class="">extension<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d7278" class="">String</span><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">bridge</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> </span><font color="#eb7100" face="Menlo" class="">NSURL</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class="">? {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">return</span> </span><font color="#eb7100" face="Menlo" class="">NSURL</font><font color="#424242" face="Menlo" class="">(string: </font><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">self</span><font color="#424242" face="Menlo" class="">)</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><p style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66); min-height: 14px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">bridge</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> </span><font color="#eb7100" face="Menlo" class="">NSURLComponents</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class="">? {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">return</span> </span><font color="#eb7100" face="Menlo" class="">NSURLComponents</font><font color="#424242" face="Menlo" class="">(string: </font><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">self</span><font color="#424242" face="Menlo" class="">)</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(235, 113, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span>NSURLComponents<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">bridge</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> </span><font color="#eb7100" face="Menlo" class="">NSURL</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class="">? {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(255, 47, 146);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span>return<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span>self<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class="">.URL</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div></div><div class=""><br class=""></div><div class="">Now this is how Swift-to-Foundation bridge could be implemented with this new syntax : </div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(255, 47, 146);" class="">extension<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #eb7100" class="">NSNumber</span><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">bridge</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> </span><font color="#3d7278" face="Menlo" class="">Int</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">self</span>.integerValue</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(255, 47, 146);" class="">extension<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d7278" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">bridge</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> </span><font color="#eb7100" face="Menlo" class="">NSNumber</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">return</span> </span><font color="#eb7100" face="Menlo" class="">NSNumber</font><font color="#424242" face="Menlo" class="">(integerValue: </font><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">self</span><font color="#424242" face="Menlo" class="">)</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div></div></div><div class=""><br class=""></div><div class="">Then, as soon a bridge is defined from a type A to a type B, anywhere an API expects to have a type B, we could pass a type A instead :</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">enum</span> </span><font color="#3d7278" face="Menlo" class="">AppColors</font><font color="#424242" face="Menlo" class=""> {</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">case</span> PrimaryTextColor</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">case</span> SecondaryTextColor</div><p style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66); min-height: 14px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">bridge</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> </span><font color="#eb7100" face="Menlo" class="">UIColor</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(255, 47, 146);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span>switch<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span>self<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">case</span> .</span><font color="#59aba0" face="Menlo" class="">PrimaryTextColor</font><font color="#424242" face="Menlo" class="">:</font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">return</span> </span><font color="#eb7100" face="Menlo" class="">UIColor</font><font color="#424242" face="Menlo" class="">.blackColor()</font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">case</span> .</span><font color="#59aba0" face="Menlo" class="">SecondaryTextColor</font><font color="#424242" face="Menlo" class="">:</font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">return</span> </span><font color="#eb7100" face="Menlo" class="">UIColor</font><font color="#424242" face="Menlo" class="">.grayColor()</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">...</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">let</span> cell = <span style="font-variant-ligatures: no-common-ligatures; color: #eb7100" class="">UITableViewCell</span>(style: .<span style="font-variant-ligatures: no-common-ligatures; color: #59aba0" class="">Value1</span>, reuseIdentifier: <span style="font-variant-ligatures: no-common-ligatures; color: #d81e00" class="">"MyCell"</span>)</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d68945" class="">cell</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #d68945" class="">textLabel</span>?.textColor = .</span><font color="#59aba0" face="Menlo" class="">PrimaryTextColor</font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #d68945" class="">cell</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #d68945" class="">detailTextLabel</span>?.textColor = .</span><font color="#59aba0" face="Menlo" class="">SecondaryTextColor</font></div></div><div class=""><br class=""></div><div class="">We could also imagine that bridges support error throwing : </div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(255, 47, 146);" class="">extension<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d7278" class="">String</span><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">enum</span> ColorBridgeError: <span style="font-variant-ligatures: no-common-ligatures; color: #eb7100" class="">ErrorType</span> {</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">case</span> ColorNameNotSupported</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">bridge</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">throws</span> </span><font color="#eb7100" face="Menlo" class="">UIColor</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(255, 47, 146);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span>switch<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span>self<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> {</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">case</span> <span style="font-variant-ligatures: no-common-ligatures; color: #d81e00" class="">"red"</span>:</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">return</span> </span><font color="#eb7100" face="Menlo" class="">UIColor</font><font color="#424242" face="Menlo" class="">.redColor()</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">case</span> <span style="font-variant-ligatures: no-common-ligatures; color: #d81e00" class="">"blue"</span>:</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">return</span> </span><font color="#eb7100" face="Menlo" class="">UIColor</font><font color="#424242" face="Menlo" class="">.blueColor()</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(255, 47, 146);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #424242" class=""> </span>default<span style="font-variant-ligatures: no-common-ligatures; color: #424242" class="">:</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">throw</span> </span><font color="#3d7278" face="Menlo" class="">ColorBridgeError</font><font color="#424242" face="Menlo" class="">.</font><font color="#59aba0" face="Menlo" class="">ColorNameNotSupported</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">...</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">do</span> {</div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><span style="font-family: Menlo; color: rgb(214, 137, 69);" class="">cell</span><font color="#424242" face="Menlo" class="">.</font><span style="font-family: Menlo; color: rgb(214, 137, 69);" class="">textLabel</span><font color="#424242" face="Menlo" class="">?.textColor = </font><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">try</span> <font color="#ff2f92" face="Menlo" class="">self</font><font color="#424242" face="Menlo" class="">.</font><font color="#d68945" face="Menlo" class="">colorNameTextField</font><font color="#424242" face="Menlo" class="">.text</font></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">self</font><font color="#424242" face="Menlo" class="">.</font><font color="#d68945" face="Menlo" class="">errorLabel</font><font color="#424242" face="Menlo" class="">.text = </font><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">nil</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ff2f92" class="">catch</span> </span><font color="#3d7278" face="Menlo" class="">String</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class="">.ColorBridgeError.</span><font color="#59aba0" face="Menlo" class="">ColorNameNotSupported</font><font color="#424242" face="Menlo" class=""> {</font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> </span><font color="#ff2f92" face="Menlo" class="">self</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class="">.</span><font color="#d68945" face="Menlo" class="">errorLabel</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class="">.text = </span><font color="#d81e00" face="Menlo" class="">"This color name is invalid :("</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div></div><div class=""><br class=""></div><div class="">This implementation is of course one of many implementations possible and I'm really open to suggestions. For instance I already can see one trade-off of this implementation : for the <font color="#3d7278" face="Menlo" class="">String</font><font color="#424242" face="Menlo" class=""> -> </font><font color="#eb7100" face="Menlo" class="">NSURL</font><font color="#424242" face="Menlo" class="">?</font> bridge, why <font color="#eb7100" face="Menlo" class="">NSURL</font><font color="#424242" face="Menlo" class="">(string: </font><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">self</span><font color="#424242" face="Menlo" class="">)</font> would be chosen over <font color="#eb7100" face="Menlo" class="">NSURL</font><font color="#424242" face="Menlo" class="">(fileURLWithPath: </font><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">self</span><font color="#424242" face="Menlo" class="">)</font> ? </div><div class=""><br class=""></div><div class="">We could also image than bridge are "chainable" (but maybe it could affect compilation times ?). For instance </div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font color="#ff2f92" class="">extension</font><span style="color: rgb(66, 66, 66);" class=""> </span><font color="#eb7100" class="">A</font><span style="color: rgb(66, 66, 66);" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">bridge</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> </span><font color="#eb7100" face="Menlo" class="">B</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="color: rgb(255, 47, 146);" class="">return</span> </span><font color="#eb7100" face="Menlo" class="">B</font><font color="#424242" face="Menlo" class="">(withA: </font><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">self</span><font color="#424242" face="Menlo" class="">)</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div></div></div><div class=""><br class=""></div><div class=""><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font color="#ff2f92" class="">extension</font><span style="color: rgb(66, 66, 66);" class=""> </span><font color="#eb7100" class="">B</font><span style="color: rgb(66, 66, 66);" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><font color="#424242" face="Menlo" class=""> </font><font color="#ff2f92" face="Menlo" class="">bridge</font><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> </span><span style="font-family: Menlo;" class=""><font color="#eb7100" class="">C</font></span><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-family: Menlo; color: rgb(66, 66, 66);" class=""> <span style="color: rgb(255, 47, 146);" class="">return</span> </span><span style="font-family: Menlo;" class=""><font color="#eb7100" class="">C</font></span><font color="#424242" face="Menlo" class="">(withB: </font><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">self</span><font color="#424242" face="Menlo" class="">)</font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class=""> }</div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(66, 66, 66);" class="">}</div></div></div><div class=""><br class=""></div><div class=""><font color="#ff2f92" face="Menlo" class="">func</font><font color="#424242" face="Menlo" class=""> doSomethingWithC(anyC: </font><font color="#eb7100" face="Menlo" class="">C</font><font color="#424242" face="Menlo" class="">) {</font></div><div class=""><font color="#424242" face="Menlo" class=""> //...</font></div><div class=""><font color="#424242" face="Menlo" class="">}</font></div><div class=""><font color="#424242" face="Menlo" class=""><br class=""></font></div><div class=""><span style="font-family: Menlo; color: rgb(255, 47, 146);" class="">let</span><span style="color: rgb(66, 66, 66); font-family: Menlo;" class=""> a = </span><span style="font-family: Menlo; color: rgb(235, 113, 0);" class="">A</span><font color="#424242" face="Menlo" class="">()</font></div><div class=""><span style="color: rgb(66, 66, 66); font-family: Menlo;" class="">doSomethingWithC(a) // Compiler could </span><font color="#424242" face="Menlo" class="">implicitly bridge `a` to type `B`, then bridge the result to type `C`</font></div><div class=""><font color="#424242" face="Menlo" class=""><br class=""></font></div><div class="">But this is optional for the feature, we could imagine to explicitly need to implement a bridge from A to C.</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Well, I think that's all for now. I hope it was not too long to read and it was well explained. I'm of course open to all suggestions, questions, enhancements, etc...</div><div class=""><br class=""></div><div class="">I would also be happy to have technical details about possible implementations as I'm not an expert at all in compiler design. I really don't know how this feature could affect the compiler and any insight here will be welcome.</div><div class=""><br class=""></div><div class="">Thanks for reading.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Jérôme Alves</div><div class=""><br class=""></div><div class=""><br class=""></div></body></html>