Update title of NSMenuItem in Menu Bar on Mac Catalyst Based on Current Context?

I'm using UIMenuBuilder API to add a menu item to the menu bar on Mac Catalyst (adding a UIKeyCommand object).

So depending on the current selection the title of the menu item should change. As an example in Finder if a single file is selected and you go to the "Edit" menu in the menu bar there is an item that says "Copy Filename"

Now select two files in Finder and go to Edit menu in the menu bar and now it says "Copy 2 Items"

Updating a NSMenuItem in Appkit is pretty easy. I figured I'd be able to do this in -canPerformAction:withSender: but the system doesn't pass my UIKeyCommand as the sender but instead an instance of a private class _UIMenuBarItem. I assume there must be a way to dynamically update the title of a menu bar item in a Catalyst app?

Ah nice I found the answer. I have to override the -validateCommand: method.

Accepted Answer

Ah nice I found the answer. I have to override the -validateCommand: method.

Update title of NSMenuItem in Menu Bar on Mac Catalyst Based on Current Context?
 
 
Q