<div dir="ltr">Ehrm, correction:<div><div>If initializers were void-functions in every aspect, how would we explain what happens here:</div><div>let a: Int = Int.init(123)</div><div>let b: Int? = Int.init("ff", radix: 16)</div><div>print(a) // 123</div><div>print(b) // Optional(255)</div><div>?</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 9, 2016 at 12:41 PM, Jens Persson <span dir="ltr"><<a href="mailto:jens@bitcycle.com" target="_blank">jens@bitcycle.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"><span class=""><br>> Swift, on the other hand, is different:<br>> Init-methods are void-functions in every aspect, with the irregularity</span><div><span class="">> that we can return "nil" (if the initializer is marked accordingly).</span><div><div class="gmail_extra"><br></div><div class="gmail_extra">Initializers are clearly not void-functions, as they return a value of type T.</div><div class="gmail_extra">And failable initializers return an Optional<T>.</div><div class="gmail_extra">Where T is the type to which the initializer belongs.</div><div class="gmail_extra"><br></div><div class="gmail_extra">If initializers where void-functions in every aspect, how would we explain what happens here:</div><div class="gmail_extra"><div class="gmail_extra">let a: Int = Int.init(123)</div><div class="gmail_extra">let b: Int? = Int.init("ff", radix: 16)</div><div class="gmail_extra">print(a) // 123</div><div class="gmail_extra">print(b) // 255</div><div>?</div><div><br></div><div>/Jens</div><div><br></div></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Wed, Mar 9, 2016 at 11:32 AM, Tino Heth via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></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">As ease of use and performance implications have been discussed, I would still like to see the question of consistency addressed:<br>
In Objective-C, returning nil from an initializer is nothing special — it is a regular function that returns id (self in most cases).<br>
<br>
Swift, on the other hand, is different:<br>
Init-methods are void-functions in every aspect, with the irregularity that we can return "nil" (if the initializer is marked accordingly).<br>
<br>
Am I the only one who has the feeling that this is a little bit odd?<br>
What kind of method is a initializer in Swift?<br>
<br>
Tino<br>
<div><div><br>
_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div>bitCycle AB | Smedjegatan 12 | 742 32 Östhammar | Sweden<br><a href="http://www.bitcycle.com/" target="_blank">http://www.bitcycle.com/</a><br>Phone: +46-73-753 24 62<br>E-mail: <a href="mailto:jens@bitcycle.com" target="_blank">jens@bitcycle.com</a><br><br></div>
</font></span></div></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">bitCycle AB | Smedjegatan 12 | 742 32 Östhammar | Sweden<br><a href="http://www.bitcycle.com/" target="_blank">http://www.bitcycle.com/</a><br>Phone: +46-73-753 24 62<br>E-mail: <a href="mailto:jens@bitcycle.com" target="_blank">jens@bitcycle.com</a><br><br></div>
</div>