> On Dec 28, 2015, at 10:46 AM, Félix Cloutier <[email protected]> wrote:
>
> Would it be possible to add properties to closures/method objects?
>
> Right now, it's possible to write:
>
>> @objc
>> class Foo : NSObject {
>> func doSomething(value: Int) -> Int {
>> return value + 1
>> }
>> }
>>
>> let method = Foo.doSomething
>
> Maybe we could have Foo.doSomething.selector for @objc methods?
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:
let fptr: @convention(c) (Double) -> Double = sqrt
to get the function pointer for `sqrt`, you could say:
let sel: Selector = Foo.doSomething
to get the selector for `doSomething`.
-Joe
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution