[swift-evolution] [Idea] Expression to retrieve the Objective-C selector of a method
Félix Cloutier
felixcca at yahoo.ca
Mon Dec 28 13:22:58 CST 2015
I really only was talking about the case where the compiler knows that it's an @objc method (with the understanding that the information is lost as soon as you make an unattributed T -> U closure out of it).
Either syntax would make me happy.
Félix
> Le 28 déc. 2015 à 13:49:22, Joe Groff <jgroff at apple.com> a écrit :
>
>>
>> On Dec 28, 2015, at 10:46 AM, Félix Cloutier <felixcca at yahoo.ca <mailto:felixcca at yahoo.ca>> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151228/24346a5b/attachment.html>
More information about the swift-evolution
mailing list