<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This is something I'm looking into. Providing the getter is valuable, but setters are not usually very useful by themselves. With value types, you need the full property interface to be able to drill further down into the value and update part of the value, since you potentially need recursive writeback. Furthermore, the get/set protocol is inefficient for copy-on-write types, since it forces a temporary copy when doing partial updates; Swift's property model provides a third implicit "materializeForSet" accessor that preserves in-place update when going through abstractions such as overrideable class properties, properties in generics, or properties across resilience boundaries. There are even more shenanigans we're planning to make mutations through array slices and the like efficient too. To that end, I think the two things you want of a property are:<div class=""><br class=""></div><div class="">- its getter, since read-only access is definitely useful for things like `map`, and</div><div class="">- what i'll call its "lens", notionally a function T -> inout U, which captures the full property interface. You can apply the function in mutable contexts without sacrificing efficiency or composability, and derive the getter/setter functions fairly straightforwardly.</div><div class=""><br class=""></div><div class="">-Joe</div><div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On Dec 13, 2015, at 4:34 PM, Michael Henson 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 dir="ltr" class="">Swift-like full KVO/KVC as in Objective-C is a stated long-term goal for Swift's evolution. The 90% solution might be more straightforward:<br class=""><br class="">class Example {<div class=""> var member: String</div><div class=""><br class=""></div><div class=""> func print() {</div><div class=""> print(self.member)</div><div class=""> }</div><div class="">}<br class=""><br class="">var example = Example(member: "Hi!")<br class=""><br class="">var example_print_method = example.print</div><div class="">example_print_method()</div><div class="">result:</div><div class="">Hi!<br class=""><br class=""></div><div class="">If there were a mechanism for referring to the getter and setter methods on the var member property as the same kind of self-capturing closures, it could make simple cases of data binding easier to implement:<br class=""><br class="">var serializeFields = [<br class=""> "member": example.member#get,<br class="">]<br class=""><br class="">var deserializeFields = [</div><div class=""> "member": example.member#set,</div><div class="">]<br class=""><br class="">var broadcastValueTo = [</div><div class=""> "memberValues": [</div><div class=""> example.member#set,</div><div class=""> example2.member#set,</div><div class=""> example3.member#set,</div><div class=""> ]</div><div class="">]</div><div class=""><br class=""></div><div class="">viewController.textField.onValueChanged(example.member#set)<br class=""><br class="">Etc.<br class=""><br class="">The "#" notation is just a placeholder for "whatever mechanism is decided upon", though it does seem to be available and using it postfix makes a first-glance sense to me in terms of the semantics of expressions.<br class=""><br class="">Mike</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RoDF4MveSEMYBIqIJA6ub1g8cOZ-2BVYvqV-2FqygPhjPn9K6-2B-2BOoX8WSqEt2FYNfGr-2Bo0FgLPaSF7hDgINEU71hRVCsib-2B9zXQL4WH71BGc5tKxvQo19hMI2AbNCeUXVCFyXV1i4OBUzt1th3tmC8E1El8-2BWVW4gsK5GxIoQ-2BAkHS0s471KGj-2FbEtVpB8q5NGaTc0sVRTjTSqBqQvRgjMom4A-3D-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></body></html>