In Swift, how do I execute the Cocoa target-action pattern with a selector determined at runtime?
The specifics at hand:
My code receives a UIBarButtonItem
, and it needs invoke the action that button represents. In Objective-C, it's straightforward:
UIBarButtonItem* button = ...;
[button.target performSelector: button.action withObject: self];
In Swift, performSelector:
is not exposed for type/memory safety reasons. I can't create a Swift closure since I don't know the button.action at compile time. Any other technique for invoking the action?