<div dir="ltr">On 8 November 2017 at 14:20, Mike Kluev <span dir="ltr">&lt;<a href="mailto:mike.kluev@gmail.com" target="_blank">mike.kluev@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><span class="gmail-">On 8 November 2017 at 10:54, Benjamin G <span dir="ltr">&lt;<a href="mailto:benjamin.garrigues@gmail.com" target="_blank">benjamin.garrigues@gmail.com</a>&gt;</span> wrote:<br></span><div class="gmail_extra"><div class="gmail_quote"><span class="gmail-"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">All your use cases make perfect sense, however i see one potential issue with this &quot;pattern&quot; : <div><br></div><div>I&#39;ve seen a LOT of iOS developers (some juniors, some not) ending up with monstruous UIViewControllers, and it has happened almost since the very beginning of iOS development. Because of their lack of understanding of the MVC pattern, they completely under estimate either the model or the view layer and put too many things in their VC. </div><div><br></div><div>Now this pattern would give them the illusion that they&#39;re working in a sane architecture and that they&#39;ve decomposed the problem correctly, but in fact were not. The fact that extension wouldn&#39;t let you add variable makes it harder to conceal the problem, but with &quot;continuations&quot; i can see no limit.</div><div><br></div><div>What do you think ? </div><div><br></div></div></blockquote><div><br></div></span><div>good tools won&#39;t fix bad developers (c)</div><div><br></div><div>you know that you can already sort of &quot;store variables&quot; in extensions, right? obj-c associated object is one way (1). and if we are talking about the use case of extending &quot;your own types only&quot; -- i am -- your own classes are under your full control, so nobody stops you from having, say, an &quot;extensionVars&quot; dictionary in your root class(es) and a handy set of generic api&#39;s to get/set those in a convenient manner without too much effort (2). is it ideal? no. performance suffers. usability suffers. non trivial to have weak/unowned variables with (2). not a &quot;first class citizen&quot; solution. the sheer number of hits of &quot;how to i store variables in extensions in swift&quot; (more than a million now) hints you that the language can step in to help, at least in the critical use case of &quot;own types&quot;.</div><span class="gmail-HOEnZb"><font color="#888888"><div><br></div></font></span></div></div></div></blockquote><div><br></div><div>ftm, this is what i have now (based on method 2):</div><div><br></div><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,143,0)"><span style="color:rgb(4,51,255)">extension</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(52,149,175)">SomeClass</span><span style="color:rgb(0,0,0)"> </span>/* FeatureX */<span style="color:rgb(0,0,0)"> {</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px">    </p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    <span style="color:rgb(4,51,255)">var</span> someVar: <span style="color:rgb(52,149,175)">Float</span> {</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">get</span> { <span style="color:rgb(4,51,255)">return</span> extensionVar() }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">set</span> { setExtensionVar(newValue) }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px">    </p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    <span style="color:rgb(4,51,255)">var</span> otherVar: <span style="color:rgb(52,149,175)">Bool</span> {</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">get</span> { <span style="color:rgb(4,51,255)">return</span> extensionVar() }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">set</span> { setExtensionVar(newValue) }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px">    </p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    <span style="color:rgb(4,51,255)">var</span> someOptionalVar: <span style="color:rgb(52,149,175)">Int</span>? {</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">get</span> { <span style="color:rgb(4,51,255)">return</span> extensionVarOpt() }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">set</span> { setExtensionVarOpt(newValue) }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px">    </p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    <span style="color:rgb(4,51,255)">func</span> initFeatureX() {</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,143,0)"><span style="color:rgb(0,0,0)">        </span>// init is optional if you can trust your code doing &quot;set&quot; before the first &quot;get&quot;</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        someVar = 0</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        otherVar = <span style="color:rgb(4,51,255)">false</span></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    }</p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">}</p>
<p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Helvetica;min-height:14px"><br></p><p style="margin:0px;font-stretch:normal;line-height:normal;min-height:14px">this is on the use side. &quot;not too bad&quot;. not too insane syntax. not too much code on the use side. note that i don&#39;t even have to spell the keys explicitly, so it is the same copy-paste code for all the variables. but then... optional vars need a different syntax. no weak/unowned support. non-optional ones need to be &quot;set before get&quot;. performance suffers. etc, etc... (see the above).<br></p><p style="margin:0px;font-stretch:normal;line-height:normal;min-height:14px"><br></p><p style="margin:0px;font-stretch:normal;line-height:normal;min-height:14px">this is the ideal i am dreaming of:</p><p style="margin:0px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Helvetica;min-height:14px"><br></p>
<p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">part FeatureX SomeClass {</p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    <span style="color:rgb(4,51,255)">var</span> someOptionalVar: <span style="color:rgb(52,149,175)">Int</span>? {</p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">var</span> someVar: <span style="color:rgb(52,149,175)">Float</span> = 0</p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">var</span> otherVar: <span style="color:rgb(52,149,175)">Bool</span> = <span style="color:rgb(4,51,255)">false</span></p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">var</span> someOptionalVar: <span style="color:rgb(52,149,175)">Int</span>?</p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px">        </p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">        <span style="color:rgb(4,51,255)">weak</span> <span style="color:rgb(4,51,255)">var</span> someWeakVar: <span style="color:rgb(52,149,175)">X</span>?</p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">    }</p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">







</p><p style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)">}</p><div><br></div><div>parts (continuations) can be an answer.</div><div><br></div><div>Mike</div><div><br></div></div></div></div>