<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 Dec 28, 2015, at 10:46 AM, FĂ©lix Cloutier <<a href="mailto:felixcca@yahoo.ca" class="">felixcca@yahoo.ca</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Would it be possible to add properties to closures/method objects?</div><div class=""><br class=""></div><div class="">Right now, it's possible to write:</div><div class=""><br class=""></div><div class=""><div class=""></div></div><blockquote type="cite" class=""><div class=""><div class="">@objc</div><div class="">class Foo : NSObject {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>func doSomething(value: Int) -> Int {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>return value + 1</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class="">}</div></div><div class=""><br class=""></div><div class="">let method = Foo.doSomething</div></blockquote><div class=""><br class=""></div><div class="">Maybe we could have Foo.doSomething.selector for @objc methods?</div></div></div></blockquote></div><br class=""><div class="">Once you have a normal function value, it's not guaranteed you can recover any identity from it, since an arbitrary T -> U doesn't necessarily correspond to an @objc method. I'm proposing we do this by type context, similar to how we form C function pointers and blocks. Just like you can do:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">let fptr: @convention(c) (Double) -> Double = sqrt</div><div class=""><br class=""></div></blockquote>to get the function pointer for `sqrt`, you could say:<div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">let sel: Selector = Foo.doSomething</div><div class=""><br class=""></div></blockquote>to get the selector for `doSomething`.<div class=""><br class=""></div><div class="">-Joe</div></body></html>