<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=""> <br class=""><div><blockquote type="cite" class=""><div class="">On 25. Jul 2017, at 18:30, Taylor Swift via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></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="">
guard<br class="">
let someProperty = data["some_key"],<br class="">
let anotherProperty = data["another_key"]<br class="">
else {<br class="">
return nil<br class="">
}<br class="">
<br class="">
self. someProperty = someProperty<br class="">
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="">
init?(data: [String: Any]) {<br class="">
guard<br class="">
someProperty = data["some_key"], // Currently fails because `self` us used before all stored properties are initialized<br class="">
anotherProperty = data["another_key"]<br class="">
else {<br class="">
return nil<br class="">
}<br class="">
}<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>