One thing to be aware of is the lifetime semantics. This is something that has bit me in the past when using object.functionName and passing that to another object that holds on the function: it will actually hold a strong reference to object! So it&#39;s easy to see how one can create retain cycles that way, and it&#39;s not obvious at all when reading the code (IMO)<br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 16, 2015 at 1:07 AM Adrian Kashivskyy via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">+1, I like this idea! I&#39;m not sure if I like `#`, though – maybe the type should be inferred, much like when using `init`s?<div><br></div><div></div><blockquote type="cite"><div>struct Foo {</div><div><span style="white-space:pre-wrap">        </span>init(_: Int) {}</div><div><span style="white-space:pre-wrap">        </span>init(_: String) {}</div><div>}</div><div><br></div><div>// this infers the int setter</div><div>let intInit: (Int) -&gt; Foo = Foo.init</div><div><br></div><div>// this infers the string setter</div><div>let stringInit: (String) -&gt; Foo = Foo.init<br></div></blockquote><div><br></div>Note that you cannot explicitly refer to a specific `init`. My proposal is to use the same technique when referring to getters and setters:<br><div><div><br></div><div></div><blockquote type="cite"><div>struct Foo {</div><div><span style="white-space:pre-wrap">        </span>let bar: Int</div><div>}</div><div><br></div><div>// this just reads the value</div><div>let value = Foo.bar</div><div><div><br></div><div>// this infers a getter</div><div>let getter: () -&gt; Int = Foo().bar</div><div><br></div><div>// this infers a setter</div><div>let setter: (Int) -&gt; Void = Foo().bar<br></div></div></blockquote><div><div><div><div><div>
<div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font color="#929292"><br>Pozdrawiam – Regards,</font></div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><font color="#929292">Adrian Kashivskyy</font></div>
</div>
<br><div><blockquote type="cite"><div>Wiadomość napisana przez Pierre Monod-Broca via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; w dniu 14.12.2015, o godz. 09:25:</div></blockquote></div></div></div></div></div></div></div><div style="word-wrap:break-word"><div><div><div><div><div><div><blockquote type="cite"><br><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">+1</span><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I like the #get, #set suffixes.</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I’m afraid the following would be a bit ambiguous</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"> - example.init(argument:Int, another:String)</blockquote><blockquote type="cite"> - example.subscript(index:Int)</blockquote><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Maybe with ‘#’ too</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"> - example.init#argument:Int#another:String<br> - example.init#argument#another<br> - example.init#(argument:Int, another:String)<br> - example.subscript#index:Int<br> - example.subscript#Int<br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><div><div>Pierre</div></div><br><div><blockquote type="cite"><div>Le 14 déc. 2015 à 08:57, ilya via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; a écrit :</div><br><div><div dir="ltr" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>&gt; Being able to refer to getters and setters is a good idea and aligns with being able to refer to initializers and methods.</div><div>&gt; I would also add subscripts to the list if possible.</div><div><br></div><div>Great idea! Let&#39;s discuss syntax</div><div><br></div><div>How about </div><div> - example.get.member</div><div> - example.set.member</div><div> - example.init(argument:Int, another:String)</div><div> - example.subscript(index:Int)</div><div><br></div></div><div class="gmail_extra" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br><div class="gmail_quote">On Mon, Dec 14, 2015 at 3:49 AM, Marc Knaup via swift-evolution<span> </span><span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span><span> </span>wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Wait, where is stated that KVO is a long-term goal for Swift? I might have missed that.<div><br><div>I find that one of Objective-C&#39;s most annoying features. It makes it really difficult to reason about code when things can happen unexpectedly left and right. It&#39;s the same issue with aspect-oriented programming.</div></div><div><br></div><div>I prefer explicit integration points like closures, delegates and alike.</div><div>Most times I used KVO in the past was to work around bugs or annoyances on iOS, like for example forcing a button stay enabled even when iOS disables it.</div><div><br></div><div>Also it&#39;s unlikely that all mutable properties will support observation automatically. That would require the optimizer to keep using dynamic dispatch for all of them which will hurt performance.</div><div><br></div><div><br></div><div>But I&#39;m getting off-topic since your discussion is not about KVO nor about KVC.</div><div><br></div><div>Being able to refer to getters and setters is a good idea and aligns with being able to refer to initializers and methods.</div><div>I would also add subscripts to the list if possible.</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Mon, Dec 14, 2015 at 1:34 AM, Michael Henson via swift-evolution<span> </span><span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span><span> </span>wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div dir="ltr">Swift-like full KVO/KVC as in Objective-C is a stated long-term goal for Swift&#39;s evolution. The 90% solution might be more straightforward:<br><br>class Example {<div> <span> </span>var member: String</div><div><br></div><div> <span> </span>func print() {</div><div>   <span> </span>print(self.member)</div><div> <span> </span>}</div><div>}<br><br>var example = Example(member: &quot;Hi!&quot;)<br><br>var example_print_method = example.print</div><div>example_print_method()</div><div>result:</div><div>Hi!<br><br></div><div>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><br>var serializeFields = [<br> <span> </span>&quot;member&quot;: example.member#get,<br>]<br><br>var deserializeFields = [</div><div> <span> </span>&quot;member&quot;: example.member#set,</div><div>]<br><br>var broadcastValueTo = [</div><div> <span> </span>&quot;memberValues&quot;: [</div><div>     example.member#set,</div><div>     example2.member#set,</div><div>     example3.member#set,</div><div> <span> </span>]</div><div>]</div><div><br></div><div>viewController.textField.onValueChanged(example.member#set)<br><br>Etc.<br><br>The &quot;#&quot; notation is just a placeholder for &quot;whatever mechanism is decided upon&quot;, 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><br>Mike</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=6ZGE61OxINd5lLe2xYh9Ku-2BXbixWNr2nvfzp2IB1sZh6tc4kNzfJcSTqpLpEpH526-2BDHnMIJXzBIwTZyK993UjcBHcizeFq0ouH89BEHchKyyDVYPv-2F03mof502YPS9lhbAWBeAhS-2Fu2v8-2BwutM-2FO2Epc1GCFAfJPwBGKc0YwjDX8IVV4On-2F34K2PM7RgUGXNTTX1VqCS3MEhBYrDQJDfB-2F0FVymTzFL3UbyYGnFgYI-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span> </span><br></div></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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br><br></blockquote></div><br></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1p9Jer2O6jVE9KWvo-2B9iUaEyN8slp4IizyiLwsfp54PEP1k3HuN7Q-2FAJKrF227ugqk4jUa030yyR7GFlXlLYzikP14xh5x6W2mSnFWhM2sRqtYV02AGXyRukE4KDh8tGo-2FJlDAp2PjnHKWVCngRHt-2BAbjQWeorNG5xME4E87CTrOc2mTa4quf2LJSP03y8sUIF7NyYL4JnD39lvZQx8chCYT87ynxgZBWUcuhrB7xLw-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span> </span><br>_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br><br></blockquote></div><br></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ST9LHNQ2kYRKURQJ7G-2FmGCudH8brFLVBGfh-2Becw1t9jMUkD-2FWTHCl5yIgQBEoGw1nNIbVLdA6FPslIVRdxWCwZ1otSrsRZ2vt0zREPT-2FZzDx-2FXtTVZYQPsw4G9ad-2BfZHOYLrf6dTbO0vh593RGeOEDM7ubImyBjKtw6a5MFzGkKxY-2FMJoQEGL6Z-2Bo-2FriaSsywjMiRKXJdhRsr4tRAT4fcscDrvXW7FbWlCyl4s0nKZI-3D" alt="" width="1" height="1" border="0" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span>_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=Q0Y0L54uOhrrHtFzGFlMmzHCkni7p1uaN05dut7Y5S6UE6dX8Lkx0zs8PpF0peZHFRtu2jAvzpKVnlcq2cJ2fWPp369pW0oW0wMEqQKbUVW8lhr7gHZSChWa20-2FhkN1cHEowgEG5cHW-2FCtRxsCuFSPDveW2zbxYrGx3ZraEzUhlNYiJT7K7bFBgzOx5ZOTGZmI-2BfMuj1nXc7KHOUb5C56ZLp9C452gRaWV0kDsAcoCI-3D" alt="" width="1" height="1" border="0" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span>_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">swift-evolution mailing list</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="mailto:swift-evolution@swift.org" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">swift-evolution@swift.org</a><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div></div></div></div></div></div></div><div style="word-wrap:break-word"><div><div><div><div><div><div><blockquote type="cite"></blockquote></div><br></div></div></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=EmLgVGNgdilXys3cXWyAWvOFC2-2FejnHkMVv8PyEdfbreC6FAIz9KgiGUhTLxdYl14RfbWaHLMBQIk6o32uZQTnaVOS-2FzRM-2F1GKD5e5YOCoYr8wGr1R5U8wfBjfCA0pn3C-2FozHD5TDdbssMYIDKrSAREDl4bh0ofRCx3P0gpxfImreJEgDF9MDpcDN3CYpx56y-2BDkNOvsJKKNbOAkk4KIYBkD7yMU3jTgfE49Yjei5bc-3D" alt="" width="1" height="1" border="0" style="min-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">
</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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div><div dir="ltr">-- <br></div>Javier Soto