<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="">You are proposing two things:<div class=""><div class=""><br class=""></div><div class="">1. Allow stored properties in extensions.</div><div class=""><div class="">2. Introduce an access modifier that restricts visibility to the current scope.</div><div class=""><br class=""></div><div class="">I know the first topic has been discussed quite a bit. &nbsp;I believe some of that discussion has happened on the list. &nbsp;You should be able to find it by searching the archives.</div><div class=""><br class=""></div><div class="">The second topic has also been discussed quite a bit and a proposal is being developed. &nbsp;The thread for that topic is "<font face="Helvetica Neue" class="">access control proposal”.</font></div><div class=""><font face="Helvetica Neue" class=""><br class=""></font></div><div class=""><font face="Helvetica Neue" class="">Matthew</font></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 13, 2015, at 9:19 PM, Nutchaphon Rewik via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div id="divtagdefaultwrapper" style="font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 12pt; background-color: rgb(255, 255, 255); font-family: Calibri, Arial, Helvetica, sans-serif;" class=""><div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-size: 12pt;" class="">Extension is a&nbsp;powerful feature in Swift,&nbsp;allowing&nbsp;type&nbsp;extensibility in various way. However, there are&nbsp;some&nbsp;limitations that everyone has&nbsp;to cope with. W</span><span style="font-size: 12pt;" class="">e cannot add<span class="Apple-converted-space">&nbsp;</span></span><span style="font-size: 12pt;" class="">stored variables to&nbsp;</span><font size="3" class="">extension scope. ( enclosed&nbsp;</font>variable&nbsp;<font size="3" class="">)</font><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><span style="font-size: 12pt;" class=""><br class=""></span></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">To workaround with the problem, associated object&nbsp;<font size="3" class="">has been used so far&nbsp;by m</font><span style="font-size: 12px;" class="">any Swift/Obj-c&nbsp;library that we are using today. This&nbsp;technique&nbsp;facilitates the power of&nbsp;extension.&nbsp;</span><span style="font-size: 12px;" class="">It allows extension to have enclosed&nbsp;stored&nbsp;property at runtime.&nbsp;</span><font size="3" class="">However,&nbsp;we can only&nbsp;apply this method&nbsp;to NSObject subclass type. And&nbsp;I think it&nbsp;is&nbsp;some kind of hack, and&nbsp;</font><font size="3" class="">when it comes to Swift&nbsp;the&nbsp;syntax looks&nbsp;messy.</font></div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><font size="3" class=""><br class=""></font></div><div style="margin-top: 0px; margin-bottom: 0px;" class="">So, I would like to propose an idea of storing variable inside extension scope. '<strong class="">enclose</strong>', is a prefix keyword, stating that a variable is only visible inside an extension block scope.<font size="3" class=""><br class=""></font></div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px;" class=""><br class=""></div><table cellspacing="0" width="100%" role="table" class="ms-rteTable-default" style="border-collapse: collapse; border: 1px solid rgb(198, 198, 198);"><tbody class=""><tr class=""><td class="ms-rteTable-default" style="border-collapse: collapse; border: 1px solid rgb(198, 198, 198); width: 675px;">​<span style="font-family: Menlo; font-size: 12px; color: rgb(187, 44, 162);" class="">protocol</span><span style="font-family: Menlo; font-size: 12px;" class="">&nbsp;</span><span style="color: rgb(79, 129, 135); font-family: Menlo; font-size: 12px;" class="">Incrementor</span><span style="font-family: Menlo; font-size: 12px;" class="">{</span><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(187, 44, 162);" class="">func</span>&nbsp;increase()<br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(187, 44, 162);" class="">func</span>&nbsp;otherFunc()</div><p style="margin-top: 0px; margin-bottom: 0px;" class=""></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">}<br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="color: rgb(187, 44, 162);" class="">extension</span><span style="" class="">&nbsp;</span>Incrementor<span style="" class="">{</span></div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(0, 132, 0);" class="">/*&nbsp;</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">&nbsp; &nbsp; &nbsp; &nbsp; enclose keyword only allow to be used in extension scope</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">&nbsp; &nbsp; */<br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="color: rgb(255, 0, 0);" class="">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="color: rgb(255, 0, 0);" class="">enclose</span>&nbsp;</span><span style="color: rgb(187, 44, 162);" class="">var</span><span style="" class="">&nbsp;count =&nbsp;</span><span style="color: rgb(39, 42, 216);" class="">1</span><span style="" class="">&nbsp;</span>// count is visible only in this extension scope.</div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(187, 44, 162);" class="">func</span>&nbsp;increase(){<br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span style="color: rgb(61, 29, 129);" class="">print</span>(count)<br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; count = count +&nbsp;<span style="color: rgb(39, 42, 216);" class="">1</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }<br class=""></div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">}<br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">// another extension scope</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(79, 129, 135);" class=""><span style="color: rgb(187, 44, 162);" class="">extension</span><span style="" class="">&nbsp;</span>Incrementor<span style="" class="">{</span></div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="" class="">&nbsp; &nbsp;&nbsp;</span>// can't see 'count' because it's in another extension scope.</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(187, 44, 162);" class="">func</span>&nbsp;otherFunc(){</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="color: rgb(61, 29, 129);" class="">print</span><span style="" class="">(</span>"do whatever but you will not see 'count' in this"<span style="" class="">)</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class="">}<br class=""></div></td></tr></tbody></table><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', NotoColorEmoji, 'Segoe UI Symbol', 'Android Emoji', EmojiSymbols; font-size: 12pt;" class="">This allows mixins composition style.&nbsp;</span><span style="font-family: Calibri, Arial, Helvetica, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', NotoColorEmoji, 'Segoe UI Symbol', 'Android Emoji', EmojiSymbols; font-size: 12pt;" class="">It has no side-effect to other parts, and is considered to have better separation of concerns.&nbsp;</span><span style="font-family: Calibri, Arial, Helvetica, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', NotoColorEmoji, 'Segoe UI Symbol', 'Android Emoji', EmojiSymbols; font-size: 12pt;" class="">Since we have protocol extension in Swift 2.0, this feature will empower composition scheme, and eliminates associated object hacking from Swift/Obj-c.&nbsp;</span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', NotoColorEmoji, 'Segoe UI Symbol', 'Android Emoji', EmojiSymbols; font-size: 12pt;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><font size="3" class="">Think about rewriting&nbsp;massive view controller as&nbsp;extensions&nbsp;composition. We don't have to store all states of&nbsp;the view controller class in one&nbsp;place. We can&nbsp;</font>separate<font size="3" class="">&nbsp;it to multiple part, each part consists of it own states&nbsp;using enclose keyword.</font></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', NotoColorEmoji, 'Segoe UI Symbol', 'Android Emoji', EmojiSymbols; font-size: 12pt;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><font size="3" class="">I'm pretty sure it will be very useful. So, I would like to ask the&nbsp;opinions of you guys about pros and cons of doing this. What might be an&nbsp;alternative solution</font>?&nbsp;<font size="3" class="">Is it&nbsp;consistent&nbsp;?</font></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAeHK-2BMHduZotYMN4qAPS4SOoOdF5ToQoohZcjV00UexORYJn-2FuER1E0NQNSeT3ZCKXXba7H62uc5nrYoXk7VzeAR41c0cpWD5UULlCNGPJn1n7U36draarUrDq0VSCxj4UuYYJ4DAP4-2F-2B5nsxLm2VfqbG8hEtH50mknY-2BMl-2FBFLQo4Ux6Huo5RfXAYCe1OvrBE-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span>_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></div></div></div></body></html>