[swift-users] NSInvocation equivalent
Jordan Rose
jordan_rose at apple.com
Wed Oct 5 18:24:28 CDT 2016
> On Oct 5, 2016, at 14:43, Jens Alfke via swift-users <swift-users at swift.org> wrote:
>
>
>> On Oct 5, 2016, at 1:50 PM, Bob Miller via swift-users <swift-users at swift.org> wrote:
>>
>> This is a Swift3 newbie question that I’ve not found a solution to. Has there been any consensus reached on an equivalent approach to the AppKit class NSInvocation ? Here’s a simple objC example.
>
> Swift doesn’t have an equivalent because the language simply isn’t as dynamic as Objective-C: there is no mechanism to invoke a method at runtime given its name.
>
> If you’re on an Apple platform, and the method you want to call, and its class, are @objc — then you can literally use NSInvocation from Swift to do this. But not otherwise.
However, there are usually better answers than NSInvocation (both in Swift and Objective-C). What are you actually trying to do?
Jordan
More information about the swift-users
mailing list