<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 8, 2016, at 9:23 AM, David James &lt;<a href="mailto:davidbjames1@gmail.com" class="">davidbjames1@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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="">Is this true even if there is a getter that is private? e.g. private(get) (see my latest reply before this one)</span></div></blockquote><div><br class=""></div><div>Yeah. If you can't see the getter, then the property is effectively set-only to you and has all the same problems.</div><div><br class=""></div><div>-Joe</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: 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;"><div class=""><blockquote type="cite" class=""><div class="">On Jan 8, 2016, at 5:51 PM, Joe Groff &lt;<a href="mailto:jgroff@apple.com" class="">jgroff@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Set-only properties are problematic for Swift, because it relies on being able to do writeback in many more cases than Objective-C. A set-only property will be constrained in several surprising ways. For instance, it would be impossible to drill down to a component of a set-only value type property, because this:<div class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class="">var foo: Struct { get { ... } set { ... } }</div><div class="">foo.x = value</div></blockquote><div class=""><br class=""></div><div class="">is really performing this behind the scenes:</div><div class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;">var tmp = foo // invoke getter</blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;">tmp.x = value</blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;">foo = tmp // invoke setter</blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><br class=""></blockquote>but we would have no getter in this case to initialize the temporary with. You also wouldn't be able to use the property as an 'inout' parameter or do many of the other things you expect to be able to do with a mutable property. A set-only property is so limited I don't think it really feels like a property at all anymore. These restrictions are far more obvious if you express the interface as a function rather than a property.<div class=""><br class=""></div><div class="">-Joe<br class=""><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 7, 2016, at 7:47 AM, David James 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 class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">Currently Swift has computed properties that support get or get and set, but not set only. There are use cases where we would want set only.&nbsp;<div class=""><br class=""></div><div class="">For example, toggling a boolean which changes another stored property where it would be overkill to make a method for that. It's more intuitive to just assign a boolean. e.g. myObject.myBoolean = true</div><div class=""><br class=""></div><div class="">Another example, setting an object that is introspected in order to create a new object which is then stored on a different property. The property that is stored could be readonly/get, for example. A method for the setter (e.g. setSomething) would not be as intuitive as just a plain assignment (e.g. myObject.something = ..).&nbsp;</div><div class=""><br class=""></div><div class="">Another consideration is that a pure setter would support better information hiding. You may not want the parent object to expose the property. Example scenario: set a property on an object (via assignment), which creates/modifies a stored property based on the passed (set) value, and then pass the parent object to another part of the system which can than read the stored property but<span class="Apple-converted-space">&nbsp;</span><u class="">not</u><span class="Apple-converted-space">&nbsp;</span>the original set property — i.e. you may not want to expose the original set property to another part of the system.</div><div class=""><br class=""></div><div class="">Example:</div><div class=""><br class=""></div><div class=""><div class="">var myProperty:MyClass {</div><div class="">&nbsp; &nbsp; set {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; …</div><div class="">&nbsp; &nbsp; }</div><div class="">}<br class=""></div></div><div class=""><br class=""></div><div class="">One concern is that without ‘get’ there really is no property at all, and perhaps this is the reason that pure setter was never included. However, this does not invalidate the above.</div><div class=""><br class=""></div><div class=""><div class="">As an alternative (to make it more semantically sensible) we could introduce a new keyword ‘set’, so:</div><div class=""><br class=""></div><div class=""><div class="">set myProperty:MyClass {</div><div class="">&nbsp; &nbsp; ...</div><div class="">}<br class=""></div></div><div class=""><br class=""></div><div class="">Which would support simple assignment:</div><div class=""><br class=""></div><div class="">myObject.myProperty = myOtherObject</div><div class=""><br class=""></div><div class="">Finally, it’s important to know that this is still “computed", but only computed on the input, not on the output side.</div><div class=""><div class=""><br class=""></div><div class=""><div apple-content-edited="true" class=""><div class="" style="font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="" style="font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-style-span" style="border-collapse: separate; line-height: normal; border-spacing: 0px;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">David James</div></div></span></div></span></div></span></div></div></div><br class=""></div></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RoDF4MveSEMYBIqIJA6ub1g8cOZ-2BVYvqV-2FqygPhjPn-2FOR7JLalBA2O-2BvbyM9d0NG79-2B9BA1ROwn3bo60-2BtW8pg00QZdMGLdAPyz7V-2BkyU4bKfDfFGma4F-2BnCm03J-2FtmzosiQkcaN8psZPMfDR2BGlwfe11YuTbpsLWYQ8vcX-2FIy3dOUpUNAflFuZl33aIce-2B91Wb6YoM2ZSZ3ZoaQOAL0AORly1qT46UGeLvkagXQpM-3D" alt="" width="1" height="1" border="0" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""><div class=""><div class="" style="font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="" style="font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><span class="Apple-style-span" style="border-collapse: separate; font-family: Verdana; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; border-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-stroke-width: 0px;"><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">David James</div></div></span></div></span></div></span></div></div></div></div></div></blockquote></div><br class=""></body></html>