<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Imho there is a simple solution to reach the goals of SE-0169 without breaking compatibility:<div class="">Just allow extensions inside type declarations.</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(112, 61, 170);" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><p style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">class</span><span style="color: #000000" class=""> MyVC: </span>UIViewController<span style="color: #000000" class=""> {</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> <span style="color: #ba2da2" class="">private</span> <span style="color: #ba2da2" class="">let</span> numberOfSections = <span style="color: #272ad8" class="">0</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; line-height: normal;" class=""><span style="color: #000000" class=""> </span><span style="color: #ba2da2" class="">extension</span><span style="color: #000000" class="">: </span>UITableViewDataSource<span style="color: #000000" class=""> {</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="color: #000000" class=""> </span>// Skipping the class and assume we want to extend the surrounding type</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> <span style="color: #ba2da2" class="">func</span> numberOfSections(in tableView: <span style="color: #703daa" class="">UITableView</span>) -> <span style="color: #703daa" class="">Int</span> {</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> <span style="color: #ba2da2" class="">return</span> numberOfSections</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> }</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> <span style="color: #ba2da2" class="">func</span> tableView(<span style="color: #ba2da2" class="">_</span> tableView: <span style="color: #703daa" class="">UITableView</span>, numberOfRowsInSection section: <span style="color: #703daa" class="">Int</span>) -> <span style="color: #703daa" class="">Int</span> {</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> <span style="color: #ba2da2" class="">return</span> <span style="color: #272ad8" class="">0</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> }</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> }</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; line-height: normal; color: rgb(186, 45, 162);" class=""><span style="color: #000000" class=""> </span>private<span style="color: #000000" class=""> </span>extension<span style="color: #000000" class=""> {</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="color: #000000" class=""> </span>// this would contain everything that shoudn't be visible for other extensios</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> <span style="color: #ba2da2" class="">var</span> secret: <span style="color: #703daa" class="">Int</span> = <span style="color: #272ad8" class="">0</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; line-height: normal; color: rgb(186, 45, 162);" class=""><span style="color: #000000" class=""> </span>public<span style="color: #000000" class=""> </span>extension<span style="color: #000000" class=""> </span><span style="color: #703daa" class="">MyFriendClass</span><span style="color: #000000" class=""> {</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="color: #000000" class=""> </span>// oh, well, I make an exception here for a trustworthy type</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> <span style="color: #ba2da2" class="">func</span> checkSecret(of controller: <span style="color: #4f8187" class="">MyVC</span>) -> <span style="color: #703daa" class="">Bool</span> {</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> <span style="color: #ba2da2" class="">return</span> controller.secret > <span style="color: #272ad8" class="">0</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> }</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> }</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; line-height: normal; color: rgb(186, 45, 162);" class=""><span style="color: #000000" class=""> </span>private<span style="color: #000000" class=""> </span>extension<span style="color: #000000" class=""> {</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="color: #000000" class=""> </span>// this is so secret, I'm not even allowed to copy it</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> }</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> }</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class=""><br class=""></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> <span style="color: #ba2da2" class="">public</span> <span style="color: #ba2da2" class="">func</span> myMethod() {</p>
<p style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);" class=""><span style="color: #000000" class=""> </span><span style="color: #3e1e81" class="">print</span><span style="color: #000000" class="">(</span>"This is just a boring method"<span style="color: #000000" class="">)</span></p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""> }</p>
<p style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class="">}</p><div class=""><br class=""></div></div></div></div></div></div></div><div class="">It has the downside of shifting code to the right (you could as well leave those extension-blocks unindented), but lots of advantages:</div><div class="">- No change for private needed</div><div class="">- It can be nested as much as you like to satisfy even the most absurd desires of encapsulation</div><div class="">- It reminds me on operator definitions inside type declarations </div><div class="">- No change for fileprivate needed (but actually, I think there is very little need to keep fileprivate)</div><div class=""><br class=""></div><div class="">I wish this would only be a joke, but writing the example, I actually started liking the concept (but I have a terrible headache right now which might affect my mind) — so either this receives some feedback, or I might start re-proposing this ;-)</div><br class=""><div class="">- Tino</div></body></html>