<div dir="ltr"><div>For reference, it can also be found in The Swift Programming Language Guide under Access Control › Constants, Variables, Properties, and Subscripts › <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AccessControl.html#//apple_ref/doc/uid/TP40014097-CH41-ID18">Getters and Setters</a>.<br><br>&gt; You can give a setter a <i>lower</i> access level than its 
corresponding getter, to restrict the read-write scope of that variable,
 property, or subscript. You assign a lower access level by writing <code class="">private(set)</code> or <code class="">internal(set)</code> before the <code class="">var</code> or <code class="">subscript</code> introducer.<br><br></div>—Johan<br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 4, 2015 at 8:57 PM, Evan Maloney <span dir="ltr">&lt;<a href="mailto:emaloney@gilt.com" target="_blank">emaloney@gilt.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>Very cool! I hadn&#39;t seen that in use anywhere; glad I sent my e-mail or I wouldn&#39;t know it exists. :)</div><div><br></div><div>Thanks, Jordan!</div><div><div class="h5"><div><br></div><div><br></div><div><br><div><blockquote type="cite"><div>On Dec 4, 2015, at 2:50 PM, Jordan Rose &lt;<a href="mailto:jordan_rose@apple.com" target="_blank">jordan_rose@apple.com</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word"><div>We have this, actually! It&#39;s spelled &quot;private(set)&quot; on the property.</div><div><br></div><div>We probably will need a way to put attributes on stored property accessors, though. @objc for custom getter or setter names is an interesting one already.</div><div><br></div><div>Jordan</div><div><br></div><br><div><blockquote type="cite"><div>On Dec 4, 2015, at 11:48 , Evan Maloney &lt;<a href="mailto:emaloney@gilt.com" target="_blank">emaloney@gilt.com</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">Currently, Swift supports a single level of access controls for properties. If a read/write property is declared as public, both the getter and the setter of that property will be publicly visible.<div><br></div><div>However, it is often the case that you need a stored property that is publicly read-only but internally or privately writeable. The current way to achieve this is by doing something like:</div><div><br></div><div><div style="margin:0px;line-height:normal;font-family:&#39;Input Mono&#39;">    <span style="color:#bb2ca2">public</span> <span style="color:#bb2ca2">var</span> authenticationValidUntil: <span style="color:#703daa">NSDate</span>? {</div><div style="margin:0px;line-height:normal;font-family:&#39;Input Mono&#39;;color:rgb(79,129,135)"><span>        </span><span style="color:#bb2ca2">return</span><span> </span>_authenticationValidUntil</div><div style="margin:0px;line-height:normal;font-family:&#39;Input Mono&#39;">    }</div><div style="margin:0px;line-height:normal;font-family:&#39;Input Mono&#39;">    <span style="color:#bb2ca2">private</span> <span style="color:#bb2ca2">var</span> _authenticationValidUntil: <span style="color:#703daa">NSDate</span>?</div></div><div><br></div><div>This seems like a lot of boilerplate to achieve a common goal. Objective-C supported a similar concept by being able to declare a property as read-only in a .h file while being able to override this as a read-write property in the .m file.</div><div><br></div><div>I propose being able to declare separate access controls for a property&#39;s getter and setter, wherein the setter could have more restrictive access controls than the getter.</div><div><br></div><div>For example:</div><div><br></div><div><div style="margin:0px;line-height:normal;font-family:&#39;Input Mono&#39;">    <span style="color:rgb(187,44,162)">var</span> authenticationValidUntil: <span style="color:rgb(112,61,170)">NSDate</span>? { <span style="color:rgb(187,44,162)">public get, private set </span>}</div></div><div><br></div><div>This would result in a public getter, while the implementer could still set the value of the property.</div><div><br></div><div>Curious to get your thoughts on this.</div><div><br></div><div>Regards,</div><div><br></div><div>E. Maloney</div><div>Gilt Groupe</div><div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ZEz4qHYnXhPr3bBPu-2FxP4tN3HfWKL-2FtJpqkQ0gkOVSBgR5C72gsbnEoyI0eZEqTJSXZsN3pkj1tMHE7UyKiRykZY2dkbCY35ikJH62OMLqyLx1fG0xFHPUH7M4cB1bQ-2FLcKjT9778qwjRtiWbuYy4JpfxzstrIDaieBbpf-2FRnES9XFPCoR3oJUgFBxRM2mD2KgllQ1eS0G0UxFusGBN-2BdWhJvMjL8ciG928uXubzkt8-3D" alt="" style="min-height: 1px ! important; width: 1px ! important; border-width: 0px ! important; margin: 0px ! important; padding: 0px ! important; display: none ! important;" height="1" border="0" width="1">
</div>
_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br></div></div></blockquote></div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=KlmFWKNIEcyPEGx2Wqruu-2FaM6I0anrxIOlKS1pgqec4vgr4c7ZeLwqz-2B5dLL9IVpbFymCPT4Iuw5Mc2MY7GYxLPLcdIEiuJ1mtIYmQng9udcCbkpQkX3PK9LdCkZSEk7MJAX20yh9YRqVlBeIxXrde64cLN-2B6Ld3WTgOP95-2Fz30-2FwgBrELMTsBZJrNoWtdNWol6mAsvVVvyfGkT5Dauzgfr1xiuj8tEgXs0iKM6uKeM-3D" alt="" style="min-height: 1px ! important; width: 1px ! important; border-width: 0px ! important; margin: 0px ! important; padding: 0px ! important; display: none ! important;" height="1" border="0" width="1">
</div></div></div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div></div>