<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 13, 2016, at 9:34 AM, Kurt Werle 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=""><div class="gmail_extra">I've always thought that the with construct is not a good idea. It seems to me that the moment you want to use with it indicates that you are getting too much into some other classes business; shouldn't that class deal with this? Why are you exposing/integrating so much of some other class's logic? Maybe there should be a method that does all this, or maybe a custom struct that passes all the appropriate information...</div><div class="gmail_extra"><br class=""></div><div class="gmail_extra">Yeah, there are exceptions - always. But for the most part I'm not a fan.<br clear="all" class=""><div class=""><br class=""></div><div class="">Kurt</div></div></div></div></blockquote><br class=""></div><div>The biggest advantage of the <font face="Courier" class="">with</font> pattern IMO is Cocoa initializers. It provides a more unified </div><div>initialization scope. Instead of:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> questionLabel = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">UILabel</span><span style="font-variant-ligatures: no-common-ligatures;" class="">()</span></div></div><div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">questionLabel</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">textAlignment</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> = .</span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">Center</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">questionLabel</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">font</span><span style="font-variant-ligatures: no-common-ligatures" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">UIFont</span><span style="font-variant-ligatures: no-common-ligatures" class="">(name:</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"DnealianManuscript"</span><span style="font-variant-ligatures: no-common-ligatures" class="">, size: </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">72</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">questionLabel</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">text</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures" class="">currentQuestion</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">text</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">questionLabel</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">numberOfLines</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span></div></div><div><br class=""></div><div>You get:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> questionLabel2 = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);" class="">with</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">UILabel</span><span style="font-variant-ligatures: no-common-ligatures;" class="">()) {</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> $0.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">textAlignment</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> = .</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">Center</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> $0.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">font</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">UIFont</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(name:</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);" class="">"DnealianManuscript"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, size: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">72</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> $0.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">text</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures;" class="">currentQuestion</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">text</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> $0.</span><span style="font-variant-ligatures: no-common-ligatures;" class="">numberOfLines</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">0</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">}</span></div></div><div><br class=""></div>You also have the option to customize a Value type before assigning it to a constant or to base<div class="">a new value constant on a copy of an existing value constant:<br class=""><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">struct</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> Foo { </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> (a, b, c) = (</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"a"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"b"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">, </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"c"</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) }</span></div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);">var</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> f = </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(49, 89, 93);">with</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">Foo</span><span class="" style="font-variant-ligatures: no-common-ligatures;">()) { $0.</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">a</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> = </span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(209, 47, 27);">"X"</span><span class="" style="font-variant-ligatures: no-common-ligatures;"> }</span></div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);">print</span><span class="" style="font-variant-ligatures: no-common-ligatures;">(</span><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);">f</span><span class="" style="font-variant-ligatures: no-common-ligatures;">) </span><span class="" style="color: rgb(0, 132, 0); font-variant-ligatures: no-common-ligatures;">// Foo(a: "X", b: "b", c: "c")</span></div><div class="" style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);"><br class=""></div><div class="">I personally would love to see a Swift construct that created a scope with `self` defined so the</div><div class="">awkward `$0.` prefixes could be discarded.</div><div class=""><br class=""></div><div class="">-- E, who may have brought up this topic once or twice before on this list</div></div></div><div class=""><br class=""></div></body></html>