<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, <div class=""><br class=""></div><div class="">(this is related to: <span style="font-family: Avenir-Medium;" class=""> Type-based ‘private’ access within a file)</span></div><div class=""><br class=""><div class="">Currently class and struct items (variables, functions..) are public by default</div><div class="">that is, always accessible outside the class’s scope</div><div class="">for example: (Swift 3.1) </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=""> 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=""> </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=""> </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=""> </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=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> aPlusB() -> </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=""> {</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=""> </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=""> }</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=""> </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=""> 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=""> {</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=""> . . . </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=""> }</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=""> • All members are exposed by default, wether intended or not. This</div><div class=""> could lead to class misusage unintended by the class’s creator. </div><div class=""><br class=""></div><div class=""> • To prevent undesired access of functions vars etc. inside a class</div><div class=""> one has to prefix often too many items with the ‘private’ access modifier keyword.</div><div class=""><div class=""> Most of the functionality and items inside a class or struct are meant to </div><div class=""> be used internally and should not be revealed to the outside world. </div></div><div class=""><br class=""></div><div class=""> • It does not comply (contradicts) with lexical scope as in Swift functions etc. </div><div class=""> </div><div class=""> • It is frontally different to most other programming languages and</div><div class=""> therefore confusing for those coming from C#, C++, Java, Pascal etc. </div><div class=""><br class=""></div><div class="">I experience this as fundamentally wrong. </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 </div><div class="">need to be defined with the ‘public’ access modifier, </div><div class="">not the other way around, please. </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=""> 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=""> </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 // 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=""> </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=""> b = </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(39, 42, 216);" class="">12 // 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=""> </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=""> public </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=""> aPlusB() -> </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=""> {</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=""> </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=""> </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=""> + </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=""> }</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 style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""> func private</span><span style="font-variant-ligatures: no-common-ligatures;" class="">Function() </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; min-height: 21px;" class=""><font size="2" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Menlo" class=""> . . . </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=""> }</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’ 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.. </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 ‘protected’ keyword is needed. </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 (class only) </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. </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. </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 ‘private’ 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=""> </div><div class=""><br class=""></div></div></body></html>