<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"><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=""><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=""> self.name = nameInput.first() + " " + nameInput.last()</div><div class=""> self.dob = dateInput.datetime()</div><div class=""> If (self.age() > 18) {</div><div class=""> self.taxableStatus = INDEPENDANT</div><div class=""> } else {</div><div class=""> self.taxableStatus = DEPENDANT</div><div class=""> }</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. </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") </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); </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; </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>() </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"> 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"> 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"> self</span>.<span class="title">fontColor</span> = <span class="title">UIColor</span>.<span class="title">blackColor</span>() </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> 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. </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. </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. </div><div class=""><br class=""></div><div class=""><div class=""><!-- signature open -->-Weston<!-- signature close --></div></div></div></body></html>