advanced patterns of NSMenuItem when using NSMenu.popUpContextMenu in macOS 13.6
I need help solving I'm trying to configure I'm working on a project and hit a roadblock. I'm experiencing unexpected behavior with `NSMenuItem` when using `NSMenu.popUpContextMenu`. The context menu appears properly, but when I try to select an item, the action linked to that item is not executed. I'm developing a macOS application in Swift, and I'm using the following code to set up the context menu: ```swift let menu = NSMenu() let menuItem = NSMenuItem(title: "Do Something", action: #selector(doSomething), keyEquivalent: "") menuItem.target = self menu.addItem(menuItem) let event = NSApp.currentEvent! NSMenu.popUpContextMenu(menu, with: event, for: self.view) ``` The `doSomething` function is simple: ```swift @objc func doSomething() { print("Menu item selected") } ``` The scenario arises when I right-click to display the menu, and after selecting the item, nothing happens. I have confirmed that the `NSMenuItem` is correctly initialized and added to the menu. I tried logging the event and ensured that the action is correctly set, but the action method is never called. Additionally, I checked that the menu items are enabled and the target is set correctly. When I run the app, I don't see any errors in the console, but the lack of response from the menu item is perplexing. I've also tested this on another machine running macOS 13.6, and it behaves the same way. Has anyone faced similar issues or might there be a specific configuration Iām missing? Any help would be appreciated. I'd really appreciate any guidance on this. What would be the recommended way to handle this? Is this even possible? The stack includes Swift and several other technologies. What's the best practice here?