<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This seems like a nice compromise, though it introduces a "horizontal" issue of indentation. Not a huge issue IMHO, though I think some people may see it as a downside.<div class=""><br class=""></div><div class="">For me, it's +1, though.<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Apr 8, 2017, at 2:03 PM, Tino Heth 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 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=""><div style="margin: 0px; line-height: normal;" class=""><span style="color: #ba2da2" class="">class</span><span style="" class=""> MyVC: </span>UIViewController<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">private</span> <span style="color: #ba2da2" class="">let</span> numberOfSections = <span style="color: #272ad8" class="">0</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="" class=""> </span><span style="color: #ba2da2" class="">extension</span><span style="" class="">: </span>UITableViewDataSource<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Skipping the class and assume we want to extend the surrounding type</div><div style="margin: 0px; line-height: normal;" 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> {</div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">return</span> numberOfSections</div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" 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> {</div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">return</span> <span style="color: #272ad8" class="">0</span></div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(186, 45, 162);" class=""><span style="" class=""> </span>private<span style="" class=""> </span>extension<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// this would contain everything that shoudn't be visible for other extensios</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">var</span> secret: <span style="color: #703daa" class="">Int</span> = <span style="color: #272ad8" class="">0</span></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(186, 45, 162);" class=""><span style="" class=""> </span>public<span style="" class=""> </span>extension<span style="" class=""> </span><span style="color: #703daa" class="">MyFriendClass</span><span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// oh, well, I make an exception here for a trustworthy type</div><div style="margin: 0px; line-height: normal;" 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> {</div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">return</span> controller.secret > <span style="color: #272ad8" class="">0</span></div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; color: rgb(186, 45, 162);" class=""><span style="" class=""> </span>private<span style="" class=""> </span>extension<span style="" class=""> {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// this is so secret, I'm not even allowed to copy it</div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""> <span style="color: #ba2da2" class="">public</span> <span style="color: #ba2da2" class="">func</span> myMethod() {</div><div style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);" class=""><span style="" class=""> </span><span style="color: #3e1e81" class="">print</span><span style="" class="">(</span>"This is just a boring method"<span style="" class="">)</span></div><div style="margin: 0px; line-height: normal;" class=""> }</div><div style="margin: 0px; line-height: normal;" class="">}</div><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></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>