<div dir="ltr">I'm extremely curious to know the use case that made you code this way. Is it one of the case Adam listed before ?<div><br></div><div>I don't want to sidetrack this issue, but i wonder if something like this <a href="https://golang.org/doc/effective_go.html#embedding">https://golang.org/doc/effective_go.html#embedding</a> wouldn't be a "cleaner" solution.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 8, 2017 at 3:45 PM, Mike Kluev <span dir="ltr"><<a href="mailto:mike.kluev@gmail.com" target="_blank">mike.kluev@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class="">On 8 November 2017 at 14:20, Mike Kluev <span dir="ltr"><<a href="mailto:mike.kluev@gmail.com" target="_blank">mike.kluev@gmail.com</a>></span> wrote:<br></span><div class="gmail_extra"><div class="gmail_quote"><span class=""><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="m_2303811870110945073gmail-">On 8 November 2017 at 10:54, Benjamin G <span dir="ltr"><<a href="mailto:benjamin.garrigues@gmail.com" target="_blank">benjamin.garrigues@gmail.com</a>></span> wrote:<br></span><div class="gmail_extra"><div class="gmail_quote"><span class="m_2303811870110945073gmail-"><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 "pattern" : <div><br></div><div>I'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're working in a sane architecture and that they've decomposed the problem correctly, but in fact were not. The fact that extension wouldn't let you add variable makes it harder to conceal the problem, but with "continuations" 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't fix bad developers (c)</div><div><br></div><div>you know that you can already sort of "store variables" in extensions, right? obj-c associated object is one way (1). and if we are talking about the use case of extending "your own types only" -- i am -- your own classes are under your full control, so nobody stops you from having, say, an "extensionVars" dictionary in your root class(es) and a handy set of generic api'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 "first class citizen" solution. the sheer number of hits of "how to i store variables in extensions in swift" (more than a million now) hints you that the language can step in to help, at least in the critical use case of "own types".</div><span class="m_2303811870110945073gmail-HOEnZb"><font color="#888888"><div><br></div></font></span></div></div></div></blockquote><div><br></div></span><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 "set" before the first "get"</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. "not too bad". not too insane syntax. not too much code on the use side. note that i don'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 "set before get". 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><span class="HOEnZb"><font color="#888888"><div><br></div><div>Mike</div><div><br></div></font></span></div></div></div>
</blockquote></div><br></div>