<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. I believe some of that discussion has happened on the list. 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. 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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 powerful feature in Swift, allowing type extensibility in various way. However, there are some limitations that everyone has to cope with. W</span><span style="font-size: 12pt;" class="">e cannot add<span class="Apple-converted-space"> </span></span><span style="font-size: 12pt;" class="">stored variables to </span><font size="3" class="">extension scope. ( enclosed </font>variable <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 <font size="3" class="">has been used so far by m</font><span style="font-size: 12px;" class="">any Swift/Obj-c library that we are using today. This technique facilitates the power of extension. </span><span style="font-size: 12px;" class="">It allows extension to have enclosed stored property at runtime. </span><font size="3" class="">However, we can only apply this method to NSObject subclass type. And I think it is some kind of hack, and </font><font size="3" class="">when it comes to Swift the syntax looks 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=""> </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=""> <span style="color: rgb(187, 44, 162);" class="">func</span> increase()<br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">func</span> 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=""> </span>Incrementor<span style="" class="">{</span></div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(0, 132, 0);" class="">/* </span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""> 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=""> */<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=""> <span class="Apple-converted-space"> </span><span style="color: rgb(255, 0, 0);" class="">enclose</span> </span><span style="color: rgb(187, 44, 162);" class="">var</span><span style="" class=""> count = </span><span style="color: rgb(39, 42, 216);" class="">1</span><span style="" class=""> </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=""> <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""> <span style="color: rgb(187, 44, 162);" class="">func</span> increase(){<br class=""></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""> <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=""> count = count + <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=""> }<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=""> </span>Incrementor<span style="" class="">{</span></div><p style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; min-height: 14px;" class=""> <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=""> </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=""> <span style="color: rgb(187, 44, 162);" class="">func</span> otherFunc(){</div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="" class=""> </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=""> }</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. </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. </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. </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 massive view controller as extensions composition. We don't have to store all states of the view controller class in one place. We can </font>separate<font size="3" class=""> it to multiple part, each part consists of it own states 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 opinions of you guys about pros and cons of doing this. What might be an alternative solution</font>? <font size="3" class="">Is it consistent ?</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"> </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>