[swift-evolution] Remove Failable Initializers

Jens Persson jens at bitcycle.com
Wed Mar 9 05:57:24 CST 2016


> What kind of method is a initializer in Swift?

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.

let fnTypeA: (Int) -> Int = { Int.init($0) }
let fnTypeB: (String, Int) -> Int? = Int.init
let a = fnTypeA(123)
let b = fnTypeB("ff", 16)
print(a) // 123
print(b) // Optional(255)
print(fnTypeA.dynamicType) // Int -> Int
print(fnTypeB.dynamicType) // (String, Int) -> Optional<Int>


On Wed, Mar 9, 2016 at 11:32 AM, Tino Heth via swift-evolution <
swift-evolution at swift.org> wrote:

> As ease of use and performance implications have been discussed, I would
> still like to see the question of consistency addressed:
> In Objective-C, returning nil from an initializer is nothing special — it
> is a regular function that returns id (self in most cases).
>
> Swift, on the other hand, is different:
> Init-methods are void-functions in every aspect, with the irregularity
> that we can return "nil" (if the initializer is marked accordingly).
>
> Am I the only one who has the feeling that this is a little bit odd?
> What kind of method is a initializer in Swift?
>
> Tino
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>



-- 
bitCycle AB | Smedjegatan 12 | 742 32 Östhammar | Sweden
http://www.bitcycle.com/
Phone: +46-73-753 24 62
E-mail: jens at bitcycle.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160309/dfbf0900/attachment.html>


More information about the swift-evolution mailing list