[swift-users] NSInvocation equivalent

Jens Alfke jens at mooseyard.com
Wed Oct 5 16:43:04 CDT 2016


> 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.

—Jens


More information about the swift-users mailing list