<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>#selector(Thing.thingWatched) won't work because it expects a function. As thingWatched is a property, it doesn't know if you want to reference the getter or setter. SE-0064 lets you reference those explicitly. In this case, you could write NSStringFromSelector(#selector(getter: Thing.thingWatched)), which is far from elegant. SE-0062 is there to fix that: #keyPath(Thing.thingWatched) will return the correct string.</div><div><div><br>Sent from my iPhone</div>On 04 Jun 2016, at 16:18, Rob Napier <<a href="mailto:robnapier@gmail.com">robnapier@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">Currently KVO requires hard-coding strings to check the keypath. Does SE-0064 cover returning a string when a string is required? For example:<div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">override</span><span style=""> </span><span style="color:rgb(187,44,162)">func</span><span style=""> observeValueForKeyPath(keyPath: </span><span style="color:rgb(112,61,170)">String</span><span style="">?, </span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> ofObject object: </span><span style="color:rgb(112,61,170)">AnyObject</span><span style="">?, </span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> change: [</span><span style="color:rgb(112,61,170)">String</span><span style=""> : </span><span style="color:rgb(112,61,170)">AnyObject</span><span style="">]?,</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> context: </span><span style="color:rgb(112,61,170)">UnsafeMutablePointer</span><span style=""><</span><span style="color:rgb(112,61,170)">Void</span><span style="">>) {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">if</span> <span style="color:rgb(187,44,162)">let</span> changingThing = object <span style="color:rgb(187,44,162)">as</span>? <span style="color:rgb(79,129,135)">Thing</span>, <br></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> keyPath = keyPath </span><span style="color:rgb(187,44,162)">where</span><span style=""> </span>changingThing<span style=""> === </span><span style="color:rgb(79,129,135)">thing</span><span style=""> {</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""><br></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style=""> </span><span style="color:rgb(187,44,162)">switch</span><span style=""> keyPath {</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(187,44,162)">case</span><span style="color:rgb(0,0,0)"> </span><span style="">"thingWatched"</span><span style="color:rgb(0,0,0)">: ...</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="color:rgb(0,0,0)"><br></span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="font-family:arial,sans-serif;font-size:small;color:rgb(34,34,34)">I'd like to replace that last line with:</span><br></p></div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(187,44,162)">case</span><span style="color:rgb(0,0,0)"> #selector(Thing.thingWatched):</span></p></div><div><br></div><div>Or something similarly non-stringy.</div><div><br></div><div>Alternately, this comes back to your "Referencing Objective-C key-paths" proposal, but I'm wondering if 0064 already covers this case.</div><div><br></div><div>-Rob</div></div>
</div></blockquote></body></html>