<div dir="ltr">That last line, the value inside the Degree struct should be a Int created from a UInt32</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 7:08 PM, James Campbell <span dir="ltr"><<a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This is the full code:<div><br></div><div>
<p><span>//</span></p>
<p><span>// Box.swift</span></p>
<p><span>// Project</span></p>
<p><span>//</span></p>
<p><span>// Created by James Campbell on 06/01/2016.</span></p>
<p><span>//</span></p>
<p><span>//</span></p>
<p><span>// This File implements the Box protocol for Type Safe Alogrithm Types and other useful things.</span></p>
<p><span></span><br></p>
<p><span>import</span><span> Foundation</span></p>
<p><span></span><br></p>
<p><span>//MARK:- Box</span></p><span class="">
<p><span></span><br></p>
<p><span>protocol</span><span> Box: </span><span>CustomStringConvertible</span><span>, </span><span>CustomDebugStringConvertible</span><span> {</span></p>
<p><span> </span></p>
<p><span> </span><span>typealias</span><span> FloatLiteralType = Double</span></p>
<p><span> </span><span>typealias</span><span> IntegerLiteralType = Int</span></p>
<p><span> </span><span>typealias</span><span> BoxType = Any</span></p>
<p><span> </span></p>
<p><span> </span><span>var</span><span> value: </span><span>BoxType</span><span> { </span><span>get</span><span> </span><span>set</span><span> }</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span>()</span></p>
<p><span> </span><span>init</span><span>(</span><span>_</span><span> value: </span><span>BoxType</span><span>)</span></p>
<p><span>}</span></p>
<p><span></span><br></p>
</span><p><span>extension</span><span> </span><span>Box</span><span> </span><span>where</span><span> BoxType: CustomStringConvertible {</span></p>
<p><span> </span></p>
<p><span> </span><span>var</span><span> description: </span><span>String</span><span> {</span></p>
<p><span> </span><span>return</span><span> </span><span>self</span><span>.</span><span>value</span><span>.</span><span>description</span></p>
<p><span> }</span></p>
<p><span> </span></p>
<p><span> </span><span>var</span><span> debugDescription: </span><span>String</span><span> {</span></p>
<p><span> </span><span>return</span><span> </span><span>"</span><span>\</span><span>(</span><span>self</span><span>.</span><span>value</span><span>.</span><span>description</span><span>)"</span></p>
<p><span> }</span></p>
<p><span>}</span></p>
<p><span></span><br></p>
<p><span>//MARK: FloatingPointBox</span></p>
<p><span></span><br></p>
<p><span>protocol</span><span> FloatingPointBox: </span><span>Box</span><span>, </span><span>FloatLiteralConvertible</span><span>, </span><span>IntegerLiteralConvertible</span><span> {</span></p>
<p><span> </span></p>
<p><span> </span><span>typealias</span><span> BoxType = Double</span></p>
<p><span> </span><span>typealias</span><span> FloatLiteralConvertible = Double</span></p>
<p><span> </span><span>typealias</span><span> IntegerLiteralConvertible = Int</span></p><span class="">
<p><span>}</span></p>
<p><span></span><br></p>
<p><span>extension</span><span> </span><span>Box</span><span> </span><span>where</span><span> </span><span>Self</span><span>.BoxType == Double {</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span>(</span><span>_</span><span> value: </span><span>Double</span><span>) {</span></p>
<p><span> </span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>()</span></p>
<p><span> </span><span>self</span><span>.</span><span>value</span><span> = value</span></p>
<p><span> }</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span>(</span><span>_</span><span> value: </span><span>Int</span><span>) {</span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>()</span></p>
<p><span> </span><span>self</span><span>.</span><span>value</span><span> = </span><span>Double</span><span>(value)</span></p>
<p><span> }</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span>(</span><span>_</span><span> value: </span><span>UInt32</span><span>) {</span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>()</span></p>
<p><span> </span><span>self</span><span>.</span><span>value</span><span> = </span><span>Double</span><span>(value)</span></p>
<p><span> }</span></p>
<p><span>}</span></p>
<p><span></span><br></p>
</span><p><span>extension</span><span> </span><span>FloatLiteralType</span><span> {</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span><T: </span><span>Box</span><span> </span><span>where</span><span> </span><span>T</span><span>.</span><span>BoxType</span><span> == </span><span>Double</span><span> >(</span><span>_</span><span> box: </span><span>T</span><span>) {</span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>(box.</span><span>value</span><span>)</span></p>
<p><span> }</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span><T: </span><span>Box</span><span> </span><span>where</span><span> </span><span>T</span><span>.</span><span>BoxType</span><span> == </span><span>Int</span><span> >(</span><span>_</span><span> box: </span><span>T</span><span>) {</span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>(box.</span><span>value</span><span>)</span></p>
<p><span> }</span></p>
<p><span>}</span></p>
<p><span></span><br></p>
<p><span>extension</span><span> </span><span>CGFloat</span><span> {</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span><T: </span><span>Box</span><span> </span><span>where</span><span> </span><span>T</span><span>.</span><span>BoxType</span><span> == </span><span>Double</span><span> >(</span><span>_</span><span> box: </span><span>T</span><span>) {</span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>(box.</span><span>value</span><span>)</span></p>
<p><span> }</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span><T: </span><span>Box</span><span> </span><span>where</span><span> </span><span>T</span><span>.</span><span>BoxType</span><span> == </span><span>Int</span><span> >(</span><span>_</span><span> box: </span><span>T</span><span>) {</span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>(box.</span><span>value</span><span>)</span></p>
<p><span> }</span></p>
<p><span>}</span></p>
<p><span></span><br></p>
<p><span>//Adding FloatLiteralConvertible, IntegerLiteralConvertible</span></p>
<p><span></span><br></p>
<p><span>extension</span><span> </span><span>FloatingPointBox</span><span> </span><span>where</span><span> </span><span>Self</span><span>.BoxType == Double, </span><span>Self</span><span>.FloatLiteralConvertible == Double {</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span>(floatLiteral value: </span><span>Double</span><span>) {</span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>(value)</span></p>
<p><span> }</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span>(integerLiteral value: </span><span>Int</span><span>) {</span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>(value)</span></p>
<p><span> }</span></p>
<p><span> </span></p>
<p><span> </span><span>init</span><span><T: </span><span>IntegerType</span><span>>(</span><span>_</span><span> value: </span><span>T</span><span>) {</span></p>
<p><span> </span><span>self</span><span>.</span><span>init</span><span>(value)</span></p>
<p><span> }</span></p>
<p><span>}</span></p><p><span><br></span></p><p><span>//</span></p><p><span>// Angles.swift</span></p><p><span>// Sup</span></p><p><span>//</span></p><p><span>// Created by James Campbell on 22/12/2015.</span></p><p><span>// Copyright © 2015 Sup. All rights reserved.</span></p><p><span>//</span></p><p><span>// This File defines representations of Degrees and Radians as Type Safe Alogrithm Types</span></p><p><span></span><br></p><p><span>import</span><span> Foundation</span></p><p><span></span><br></p><p><span>//MARK:- Degree</span></p><p><span></span><br></p><p><span>struct</span><span> Degree: </span><span>FloatingPointBox</span><span> {</span></p><p><span> </span></p><p><span> </span><span>var</span><span> value: </span><span>Double</span><span> = </span><span>0</span></p><p><span> </span></p><p><span> </span><span>init</span><span>()</span></p><p><span> {</span></p><p><span> }</span></p><p><span>}</span></p><p><span></span><br></p><p><span>protocol</span><span> DegreeConvertiable {</span></p><p><span> </span></p><p><span> </span><span>init</span><span>(degreeLiteral value: </span><span>Degree</span><span>)</span></p><p><span>}</span></p><p><span></span><br></p><p><span>extension</span><span> </span><span>Degree</span><span>: </span><span>RadianConvertiable</span><span> {</span></p><p><span> </span></p><p><span> </span><span>init</span><span>(radianLiteral value: </span><span>Radian</span><span>) {</span></p><p><span> </span><span>self</span><span>.</span><span>value</span><span> = </span><span>Double</span><span>(value) * </span><span>180.0</span><span> / </span><span>M_PI</span></p><p><span> }</span></p><p><span> </span></p><p><span> </span><span>init</span><span>(</span><span>_</span><span> value: </span><span>Radian</span><span>) {</span></p><p><span> </span><span>self</span><span>.</span><span>init</span><span>(radianLiteral: value)</span></p><p><span> }</span></p><p><span>}</span></p><p><span></span><br></p><p><span>//MARK:- Radian</span></p><p><span></span><br></p><p><span>struct</span><span> Radian: </span><span>FloatingPointBox</span><span> {</span></p><p><span> </span></p><p><span> </span><span>var</span><span> value: </span><span>Double</span><span> = </span><span>0</span></p><p><span> </span></p><p><span> </span><span>init</span><span>()</span></p><p><span> {</span></p><p><span> }</span></p><p><span>}</span></p><p><span></span><br></p><p><span>protocol</span><span> RadianConvertiable {</span></p><p><span> </span></p><p><span> </span><span>init</span><span>(radianLiteral value: </span><span>Radian</span><span>)</span></p><p><span>}</span></p><p><span></span><br></p><p><span>extension</span><span> </span><span>Radian</span><span>: </span><span>DegreeConvertiable</span><span> {</span></p><p><span> </span></p><p><span> </span><span>init</span><span>(degreeLiteral value: </span><span>Degree</span><span>) {</span></p><p><span> </span><span>self</span><span>.</span><span>value</span><span> = </span><span>Double</span><span>(value) * </span><span>M_PI</span><span> / </span><span>180.0</span></p><p><span> }</span></p><p><span> </span></p><p><span> </span><span>init</span><span>(</span><span>_</span><span> value: </span><span>Degree</span><span>) {</span></p><p><span> </span><span>self</span><span>.</span><span>init</span><span>(degreeLiteral: value)</span></p><p><span> }</span></p><p><span>
</span></p><p><span>}</span></p><p><span>let someOptiona: Degreee? = nil</span></p><p>
</p><p><span> let degree = someOptional ?? Degree(arc4random_uniform(360))</span></p></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 6:57 PM, Félix Cloutier <span dir="ltr"><<a href="mailto:felixcca@yahoo.ca" target="_blank">felixcca@yahoo.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>I either don't understand or can't reproduce the issue. This code:</div><div><br></div><div></div><blockquote type="cite"><div>class Box {</div><div><span style="white-space:pre-wrap">        </span>let value: Int</div><div><span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">        </span>init(value: Int) {</div><div><span style="white-space:pre-wrap">                </span>self.value = value</div><div><span style="white-space:pre-wrap">        </span>}</div><div>}</div><div><br></div><div>let test: UInt32 = 4</div><div>let box = Box(value: test)</div></blockquote><div><br></div><div>does not compile ("foo.swift:10:22: error: cannot convert value of type 'UInt32' to expected argument type 'Int'").</div><span><font color="#888888"><div>
<br><span style="color:rgb(0,0,0);font-family:'Lucida Grande';font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;display:inline!important;float:none">Félix</span>
</div></font></span><div><div>
<br><div><blockquote type="cite"><div>Le 6 janv. 2016 à 13:17:03, James Campbell <<a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>> a écrit :</div><br><div><div dir="ltr" style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><p><span>protocol</span><span><span> </span>Box:<span> </span></span><span>CustomStringConvertible</span><span>,<span> </span></span><span>CustomDebugStringConvertible</span><span><span> </span>{</span></p><div><span> </span><br></div><p><span> <span> </span></span><span>typealias</span><span><span> </span>FloatLiteralType = Double</span></p><p><span> <span> </span></span><span>typealias</span><span><span> </span>IntegerLiteralType = Int</span></p><p><span> <span> </span></span><span>typealias</span><span><span> </span>BoxType = Any</span></p><div><span> </span><br></div><p><span> <span> </span></span><span>var</span><span><span> </span>value:<span> </span></span><span>BoxType</span><span><span> </span>{<span> </span></span><span>get</span><span><span> </span></span><span>set</span><span><span> </span>}</span></p><div><span> </span><br></div><p><span> <span> </span></span><span>init</span><span>()</span></p><p><span> <span> </span></span><span>init</span><span>(</span><span>_</span><span><span> </span>value:<span> </span></span><span>BoxType</span><span>)</span></p><p>}</p><p><span>extension</span><span><span> </span></span><span>Box</span><span><span> </span></span><span>where</span><span><span> </span></span><span>Self</span><span>.BoxType == Double {</span></p><div><span> </span><br></div><p><span> <span> </span></span><span>init</span><span>(</span><span>_</span><span><span> </span>value:<span> </span></span><span>Double</span><span>) {</span></p><div><span> </span><br></div><p><span> <span> </span></span><span>self</span><span>.</span><span>init</span><span>()</span></p><p><span> <span> </span></span><span>self</span><span>.</span><span>value</span><span><span> </span>= value</span></p><p><span> }</span></p><div><span> </span><br></div><p><span> <span> </span></span><span>init</span><span>(</span><span>_</span><span><span> </span>value:<span> </span></span><span>Int</span><span>) {</span></p><p><span> <span> </span></span><span>self</span><span>.</span><span>init</span><span>()</span></p><p><span> <span> </span></span><span>self</span><span>.</span><span>value</span><span><span> </span>=<span> </span></span><span>Double</span><span>(value)</span></p><p><span> }</span></p><div><span> </span><br></div><p><span> <span> </span></span><span>init</span><span>(</span><span>_</span><span><span> </span>value:<span> </span></span><span>UInt32</span><span>) {</span></p><p><span> <span> </span></span><span>self</span><span>.</span><span>init</span><span>()</span></p><p><span> <span> </span></span><span>self</span><span>.</span><span>value</span><span><span> </span>=<span> </span></span><span>Double</span><span>(value)</span></p><p><span> }</span></p><p><span>}</span></p><p><span><br></span></p><p><span><br></span></p><p><span>Without that last method, Swift tries to give the UInt32 to the Int version of the method which isn't safe in my eyes and I would have expected a compiler error.</span></p></div><div class="gmail_extra" style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 6:14 PM, Félix Cloutier<span> </span><span dir="ltr"><<a href="mailto:felixcca@yahoo.ca" target="_blank">felixcca@yahoo.ca</a>></span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word">I don't understand. Can you show a code example?<div><div><br><span style="font-family:'Lucida Grande';font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">Félix</span></div><br><div><blockquote type="cite"><div><div><div>Le 6 janv. 2016 à 13:02:43, James Campbell via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> a écrit :</div><br></div></div><div><div><div><div dir="ltr">I have a overloaded method for a protocol that takes an Int or double.<div><br></div><div>I have an issue with swift calling the Int version when passing in a UInt32 . Ideally I would prefer the compiler to detect I am about to do something which will cause an overflow and throw an error.</div><div><br></div><div>I would then have to explicitly add a overloaded UInt32 method or explicitly convert it to Int like so "Int(uintVariable)".<br><div><div><br></div>--<span> </span><br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank">+44 7523 279 698</a></div></div></div></div></div></div></div></div></div></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=iRI3beHTe3UxYAHTlV3lA38zIPfHMhyuRzgTmGKV6k419Va-2Fjfy307WOceC97TSnJ4yKykvotDhTuWdtGSmuCkzY650M4nROHpKCTmQcDZ02kRdLGOnAQDDmImpHoyttQmzoXSgvw2ZXpGlG2RNVrFaO1Bx6wy76nUr6VThD1LZzzgoOZj9bJN4quck7YFgENkJjy9ruI1FgHPMjI-2BQsWdZHLSKm-2B592tvIuGNC-2F6u4-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span> </span>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></blockquote></div><br><br clear="all"><div><br></div>--<span> </span><br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank">+44 7523 279 698</a></div></div></div></div></div></div></div></div></blockquote></div><br></div></div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank">+44 7523 279 698</a></div></div></div></div></div></div>
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div>+44 7523 279 698</div></div></div></div></div></div>
</div>