<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="">Hello,&nbsp;<div class=""><br class=""></div><div class="">(this is related to: &nbsp;<span style="font-family: Avenir-Medium;" class="">&nbsp; &nbsp;Type-based ‘private’ access within a file)</span></div><div class=""><br class=""><div class="">Currently class and struct items &nbsp;(variables, functions..) are public by default</div><div class="">that is, &nbsp;always accessible outside the class’s scope</div><div class="">for example: &nbsp;(Swift 3.1)&nbsp;</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">class</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;AsItIsNow</span></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font size="2" class="">{</font></span></div><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">private</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> a = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">10</span></p><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">private</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">var</span><span style="font-variant-ligatures: no-common-ligatures" class=""> b = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">12</span></font></div><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></font></p><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> aPlusB() -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font size="2" class="">&nbsp; &nbsp; {</font></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp;&nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">return</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">a</span><span style="font-variant-ligatures: no-common-ligatures" class=""> + </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">b</span></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font size="2" class="">&nbsp; &nbsp; }</font></span></div><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></p><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">private</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;helperFunction()</span></p><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font size="2" class="">&nbsp; &nbsp; {</font></span></div><p style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;. . .&nbsp;</font></span></font></p><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font size="2" class="">&nbsp; &nbsp; }</font></span></div><p style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: small;" class="">}</span></p></div><div class=""><br class=""></div><div class="">Having all items public by default has the following disadvantages:</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp;• All members are exposed by default, wether intended or not. This</div><div class="">&nbsp; &nbsp; &nbsp; could lead to class misusage unintended by the class’s creator.&nbsp;</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp;• To prevent undesired access of functions vars etc. inside a class</div><div class="">&nbsp; &nbsp; &nbsp; one has to prefix often too many items with the ‘private’ access modifier keyword.</div><div class=""><div class="">&nbsp; &nbsp; &nbsp; Most of the functionality &nbsp;and items inside a class or struct are meant to&nbsp;</div><div class="">&nbsp; &nbsp; &nbsp; be used internally &nbsp;and should &nbsp;not be revealed to the outside world.&nbsp;</div></div><div class=""><br class=""></div><div class="">&nbsp; &nbsp;• It does not comply (contradicts) &nbsp;with lexical scope as in Swift functions etc.&nbsp;</div><div class="">&nbsp;&nbsp;</div><div class="">&nbsp; &nbsp;• It is frontally different to most other programming languages and</div><div class="">&nbsp; &nbsp; &nbsp;therefore confusing for those coming from C#, C++, Java, Pascal etc.&nbsp;</div><div class=""><br class=""></div><div class="">I experience this as fundamentally wrong.&nbsp;</div><div class=""><br class=""></div><div class="">Imho it should be as in the next example, everything in a class</div><div class="">is private by default. To access/deploy items from outside they&nbsp;</div><div class="">need to be defined with the ‘public’ access modifier,&nbsp;</div><div class="">not the other way around, please.&nbsp;</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">class</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">&nbsp;AsItShouldBeImho</span></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font size="2" class="">{</font></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;a =&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">10 &nbsp;// private by default</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">var</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;b =&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">12 &nbsp; // also</span></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp;</span><br class="webkit-block-placeholder"></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;public&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">func</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;aPlusB() -&gt;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">Int</span></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font size="2" class="">&nbsp; &nbsp;&nbsp;{</font></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(186, 45, 162);" class="">return</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">a</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;+&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(79, 129, 135);" class="">b</span></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font size="2" class="">&nbsp; &nbsp;&nbsp;}</font></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: small;" class="">&nbsp; &nbsp;&nbsp;</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp; &nbsp;&nbsp;func private</span><span style="font-variant-ligatures: no-common-ligatures;" class="">Function() &nbsp;&nbsp;</span></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font size="2" class="">&nbsp; &nbsp;&nbsp;{</font></span></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp;. . .&nbsp;</font></span></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font size="2" class="">&nbsp; &nbsp;&nbsp;}</font></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: small;" class="">}</span></div></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: small;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">‘public’ &nbsp;could be an inferred attribute</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">for items defined with getters and setters..&nbsp;</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">or the compiler would demand public</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">for getters and setters..</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">The&nbsp;‘protected’&nbsp;keyword is needed.&nbsp;</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">‘protected’ would mean that the items are</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">accessible in subclasses &nbsp; (class only) &nbsp;</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">private items would also be inaccessible in</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">class extensions.&nbsp;</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">It is as yet unclear to me why it has not been done</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font size="2" class=""><font face="Avenir-Book" class="">like so from the beginning of Swift</font><font face="Avenir-Book" class="">…</font></font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">I’ve been lost in the eternal discussions over private access modifiers,</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">the volume of it makes me think that (either way in this discussions) the whole</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">scope definition is wrong in Swift .</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">especially using a file as scope limiter.&nbsp;</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">Imho there should be lexical scope only.</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">as in most other programming languages.</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">If done so correctly , one wouldn’t even need the&nbsp;‘private’&nbsp;keyword...</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">Kind Regards</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class="">TedvG</font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class=""><br class=""></font></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><a href="http://www.tedvg.com" class=""><font face="Avenir-Book" size="2" class="">www.tedvg.com</font></a></div><div style="margin: 0px; line-height: normal; min-height: 21px;" class=""><font face="Avenir-Book" size="2" class=""><a href="http://www.ravelnotes.com" class="">www.ravelnotes.com</a></font></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: small;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><div class=""><br class=""></div></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: small;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: small;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: small;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: small;" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font size="2" class=""><br class=""></font></span></div><div class="">&nbsp;</div><div class=""><br class=""></div></div></body></html>