<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="">Hey there!</div><div class=""><br class=""></div><div class="">As a suggestion, check out this simple yet very interesting project called&nbsp;<a href="https://github.com/devxoul/Then" class="">Then</a>&nbsp;by @devxoul.</div><div class=""><br class=""></div><div class="">Best,</div><div class=""><br class=""></div><div class="">— A</div><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 3, 2016, at 1:37 AM, Weston Catron 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=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><span class=""></span></div><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div class=""><span class=""></span></div><div class="">Ability to write an initializer while initializing an object.<div class=""><br class=""></div><div class="">Example</div><div class=""><br class=""></div><div class="">let name = “John Apple”;</div><div class="">let person = Person {</div><div class="">&nbsp; &nbsp; self.name = nameInput.first() + " " + nameInput.last()</div><div class="">&nbsp; &nbsp; self.dob = dateInput.datetime()</div><div class="">&nbsp; &nbsp; If (self.age() &gt; 18) {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; self.taxableStatus = INDEPENDANT</div><div class="">&nbsp; &nbsp; } else {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; self.taxableStatus = DEPENDANT</div><div class="">&nbsp; &nbsp; }</div><div class="">};</div><div class=""><br class=""></div></div><div class="">Helpful examples: Objects with many required parameters that are defaulted in the initializers.&nbsp;</div><div class=""><br class=""></div><div class="">SKLabelNode</div><div class=""><span class="title" style="background-color: rgba(255, 255, 255, 0);"><br class=""></span></div><div class=""><span class="title" style="background-color: rgba(255, 255, 255, 0);">let</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> </span><span class="title" style="background-color: rgba(255, 255, 255, 0);">label</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> = </span><span class="title" style="background-color: rgba(255, 255, 255, 0);">SKLabelNode</span><span style="background-color: rgba(255, 255, 255, 0);" class="">(</span><span class="title" style="background-color: rgba(255, 255, 255, 0);">text</span><span style="background-color: rgba(255, 255, 255, 0);" class="">: "Example")&nbsp;</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="line" style="counter-increment: lines 1;"></span>        <span class="title">label</span>.<span class="title">position</span> = <span class="title">CGPoint</span>(<span class="title">x</span>: 0, <span class="title">y</span>: 250);&nbsp;</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="line" style="counter-increment: lines 1;"></span>        <span class="title">label</span>.<span class="title">fontSize</span> = 34;&nbsp;</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="line" style="counter-increment: lines 1;"></span>        <span class="title">label</span>.<span class="title">fontColor</span> = <span class="title">UIColor</span>.<span class="title">blackColor</span>()&nbsp;</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="line" style="counter-increment: lines 1;"></span>        <span class="title">self</span>.<span class="title">addChild</span>(<span class="title">label</span>);</span></div><div class=""><br class=""></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">Can become:</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div class=""><span class="title" style="background-color: rgba(255, 255, 255, 0);">let label = SKLabelNode</span><span style="background-color: rgba(255, 255, 255, 0);" class="">(</span><span class="title" style="background-color: rgba(255, 255, 255, 0);">text</span><span style="background-color: rgba(255, 255, 255, 0);" class="">: </span><span class="title" style="background-color: rgba(255, 255, 255, 0);">self</span><span style="background-color: rgba(255, 255, 255, 0);" class="">.</span><span class="title" style="background-color: rgba(255, 255, 255, 0);">package</span><span style="background-color: rgba(255, 255, 255, 0);" class="">!.</span><span class="title" style="background-color: rgba(255, 255, 255, 0);">title</span><span style="background-color: rgba(255, 255, 255, 0);" class="">) {</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="line" style="counter-increment: lines 1;"></span><span class="title">&nbsp; &nbsp; self</span>.<span class="title">position</span> = <span class="title">CGPoint</span>(<span class="title">x</span>: 0, <span class="title">y</span>: 250)</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="title">&nbsp; &nbsp; self</span>.<span class="title">fontSize</span> = 34</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><span class="title">&nbsp; &nbsp; self</span>.<span class="title">fontColor</span> = <span class="title">UIColor</span>.<span class="title">blackColor</span>()&nbsp;</span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">}</span></div><div class="">self.addChild(label)</div><div class=""><br class=""></div><div class=""><b class="">Readability</b>&nbsp;Instead of a large amount of code setting up temporary variables to pass into an initializer, all initializing code could be wrapped in a closure.</div><div class=""><br class=""></div><div class=""><b class="">Flexibility</b> Instead of exhaustive initializers covering many use cases. Simpler initializers can be extended as needed. <span style="background-color: rgba(255, 255, 255, 0);" class="">This can also encourage required properties over optional ones that are immediately defined.&nbsp;</span></div><div class=""><br class=""></div><div class=""><b class="">Compiler Warnings</b> Closures react the same as initializers within classes, warning users of incomplete implementation of required properties.</div><div class=""><br class=""></div><div class="">Possible disadvantages:</div><div class=""><br class=""></div><div class=""><b class="">Sloppy Coding</b> Instead of writing complete initializers programmers can just rely on in-line initializers. &nbsp;</div><div class=""><br class=""></div><div class=""><b class="">Tried Before</b> I found this feature is also available in C# (<a href="https://msdn.microsoft.com/en-us/library/bb397680.aspx" class="">https://msdn.microsoft.com/en-us/library/bb397680.aspx</a>). Not sure if it was helpful then but many languages since don't appear to use it.&nbsp;</div><div class=""><br class=""></div><div class=""><div class=""><!-- signature open -->-Weston<!-- signature close --></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Q0Y0L54uOhrrHtFzGFlMm3oC4gejexfeaix2NKEDTe7al-2BNn7gXi-2BgYpHMZYRKcNHPPhou71MRB1FjaHJyGWy6wF87jbM-2FyLrvjiiABt2OSgsqAla-2F6X3xrrRMUaVTJ2p-2BYuFg-2F6Wf0L16rrZgwKk-2BDDF3BuqW-2BbedA3-2FUGJg48KbudtFjVqzbj5lcQEkPkLasnbSyXMBfRY3KOwDN7auzjcRjixw2JMivoJNBpXTDQ-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" 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=""></body></html>