<div dir="ltr"><div>&gt; What kind of method is a initializer in Swift?</div><div><br></div><div>I would say initializers are very similar to static methods taking whatever arguments and returning either T or Optional(T), depending on whether they are failable or not, where T is their enclosing type.</div><div><br></div><div>let fnTypeA: (Int) -&gt; Int = { Int.init($0) }</div><div>let fnTypeB: (String, Int) -&gt; Int? = Int.init</div><div>let a = fnTypeA(123)</div><div>let b = fnTypeB(&quot;ff&quot;, 16)</div><div>print(a) // 123</div><div>print(b) // Optional(255)</div><div>print(fnTypeA.dynamicType) // Int -&gt; Int</div><div>print(fnTypeB.dynamicType) // (String, Int) -&gt; Optional&lt;Int&gt;</div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 9, 2016 at 11:32 AM, Tino Heth via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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 &quot;nil&quot; (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 class=""><div class="h5"><br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>-- <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></div>