nyitguy nyitguy - 6 months ago 55
Swift Question

NSMenuItem updating title

I'm able to programmatically create menu items using the following code.

primaryMenu.addItem(NSMenuItem(title: "MenuTitle", action: nil, keyEquivalent: ""))

I want to be able to update the title from this menu item. I have been able to do it very easily when I manually create the menu using Interface Building.

I don't have a way to identify the menu item.


Store a reference to your NSMenuItem, and set the title on it whenever you wish:

let myMenu = NSMenuItem(title: "MenuTitle", action: nil, keyEquivalent: "")

//somewhere else:
myMenu.title = "xyz"