<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">+1.</div><div class=""><br class=""></div><div class="">&nbsp;<br class=""><div><blockquote type="cite" class=""><div class="">On 25. Jul 2017, at 18:30, Taylor Swift via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I’d be in favor of this.<br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jul 25, 2017 at 5:44 AM, philohan95 via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I think the current way to initiate models in a Failable Initializer `init?()` is overly verbose and should be shortened down so less boilerplate should be needed.<br class="">
<br class="">
The current way:<br class="">
<br class="">
```<br class="">
let someProperty: Any<br class="">
let anotherProperty: Any<br class="">
<br class="">
init?(data: [String: Any]) {<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; guard<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let someProperty = data["some_key"],<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let anotherProperty = data["another_key"]<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; else {<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return nil<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; }<br class="">
<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; self. someProperty = someProperty<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; self. anotherProperty = anotherProperty<br class="">
}<br class="">
```<br class="">
<br class="">
As you can see we had to use the properties twice (this would also be the case of `if let`) making the initializer twice as long as necessary and becomes a pain to implement when having more than 1 property.<br class="">
<br class="">
My idea is extending the power of the `guard` statement<br class="">
<br class="">
Idea:<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; init?(data: [String: Any]) {<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; guard<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; someProperty = data["some_key"], // Currently fails because `self` us used before all stored properties are initialized<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anotherProperty = data["another_key"]<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else {<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return nil<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br class="">
&nbsp; &nbsp; &nbsp; &nbsp; }<br class="">
}<br class="">
<br class="">
______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-<wbr class="">evolution</a><br class="">
</blockquote></div><br class=""></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>