UIMenuElement subclass that can take a target? Like UITargetedCommand?

When building context menus in UIKit I often have actions contained in a single method which can be invoked in different ways (from a UIButton, a UIBarButtonItem, etc.)

I'd like to simply make a menu item with a target-action pair but UICommand/KeyCommand only takes a selector. It seems kind of silly to have the system enumerate the responder chain in cases where I know who the target is supposed to be and there can and should only be one target (also could unintentionally create bugs when a responder implementing the same method gets the call instead of the target you want).

In AppKit you an easily do this with NSMenuItem. Could be a nice enhancement in UIKit. I know I can wrap the target in UIAction and call the selector in the action handler block but the code is kind of ugly and I'm not sure if there are edge cases where __weak __strong dance is required (in which case the code is even more long winded and ugly. I know swipe actions can occasionally create a retain cycle if you don't do __weak _ __strong dance).

Unless there is a UIMenuElement subclass that provides this and I'm just not aware of it?

Also this would be useful to specify targets outside the responder chain. For example I want to invoke an action from the menu bar on an object that isn't in the responder chain (it can be invoked even if my app has no open windows).

As far as I can tell my only option is to use UIAction and call the method on the "target" in the actionHandler block. But what about validating the UIAction? -canPerformAction:withSender: won't be called on the object not in the responder chain. My best bet might be subclassing UIApplication and forwarding the method calls to the target I really want.

Not sure why Apple seems to be abandoning targets. The UIKit APIs seem to be overusing blocks IMO.

UIMenuElement subclass that can take a target? Like UITargetedCommand?
 
 
Q