<div dir="ltr">a general feeling that there are two very different use cases of extensions -- one to extend own classes and another to extend other people classes; a lengthy discussion in a nearby thread; a disparity of features of class and it&#39;s extensions and different access right treatment depending upon whether the extension is in the same with the main class or a different file lead me to the following idea. hopefully you will find this idea useful and we may even see it one day in swift.<div><br></div><div>introducing class / struct / enum continuations.</div><div><br></div><div>in a few words the are:</div><div><br></div><div>1) &quot;extensions on steroids&quot;. in fact very similar to Objective-C &quot;class extensions&quot; but can be more than one and in more than one file.</div><div><br></div><div>2) as good as the classes they continue (or other continuations they continue)</div><div><br></div><div>3) can declare variables</div><div><br></div><div>4) have full access to &quot;private&quot; members of the class or other continuations</div><div>regardless whether they are in the same or in a different files. no need for &quot;public/internal/module&quot; fallbacks to pass though files boundaries. similarly the class itself can use private members of its continuations.<br></div><div><br></div><div>5) &quot;by invitation only&quot; system. can only be written if declared by the class or some continuation of it.</div><div><br></div><div>6) A particular continuation only defined once (of course). There can be an arbitrary number of different continuations to a class similar to extensions.</div><div><div><div><br></div><div>7) alternative name considered: &quot;extending&quot; (as a noun). shall definitely be a different name than say, &quot;extension&quot; with some bracket-syntax variation - the two use cases are very different and shall be named differently.</div><div><br></div><div>8) the particular syntax is preliminary of course. </div><div><br></div><div>example:</div><div><br></div><div>============= Some.swift ==================</div><div><br></div><div>class Some {</div><div><br></div><div>    private func private_method_of_class() {</div><div><br></div><div>        // *** can use private methods of continuations even if they are in a different file</div><div>        private_method_defined_in_a_continuation()</div><div>    }</div><div>    </div><div>    // *** &quot;by invitation&quot; system</div><div><br></div><div>    continuation Feature<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>// *** declaring a continuation</div><div>    continuation SomethingElse<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>// *** Capitalized names, like classes</div><div>}</div><div><br></div><div>============= Some-Feature.swift ==================</div><div><br></div><div>// *** similar naming convetion to &quot;Some+Feature.swift&quot;</div><div>// used for extensions, just with &quot;-&quot; instead</div><div><br></div><div>// *** this is merely a naming convention, no need to</div><div>necessarily follow it, can put more than one thing into</div><div>a file, the continuation can reside in the same file as</div><div>the main class fie, etc.</div><div><br></div><div>continuation Feature of Some {</div><div><br></div><div>// *** as good as class itself. first-class citizen</div><div>// *** same syntax can be used for structs and enums</div><div><br></div><div>    var x: Int // *** can declare variables</div><div>    </div><div>    private func private_method_defined_in_a_continuation() {</div><div>        private_method_of_class()</div><div><br></div><div>        // *** can use private methods of the class or of other</div><div>continuations even if they are in a different file</div><div>    }</div><div>    </div><div>    // *** continuations are as good as classes and can</div><div>    // *** declare other continuations if needed</div><div><br></div><div>    continuation CanDoThis</div><div>}</div><div><br></div><div>============= Any file ==================</div><div><br></div><div>continuation Feature of Some { // *** error, continuation is already defined</div><div>}</div><div><br></div><div>continuation Other of Some { // *** error: Other is not a continuation of Some</div><div>}</div></div><div><br></div></div><div>thoughts?</div><div><br></div><div>Mike</div><div><br></div></div>