Granted I haven't read every post - this is a long thread! - but a lot of the example cases are basically initialising a struct. In those applications, this reminds me of Java's prevalent builder pattern. That's not a compliment. Java [ab]uses that heavily because it's crippled by a lack of default function arguments, among other things. Swift doesn't have those limitations.
Point being, in all the 'init' examples I've seen, the main issue appears to be that the type being demonstrated is poorly designed - it doesn't have a suitable init
method. URLComponents
is perhaps the poster child for this, and the main example used in the SEP.
I'm yet to see anyone explain why the root problem is not simply the missing initialiser(s)…?
I get that there are other conveniences to a transient scope, but those can be achieved today using { … }()
(or by supporting simple do
expressions as discussed in Enhanced 'do' Block Syntax and Error Handling). A few more keystrokes, perhaps, but not a big deal.
I really enjoy not having Java-style builders everywhere, in Swift. I'd hate to see Swift devolve in that regard.