How can I customize the main menu bar of an OS X app?
So far, I have tried adding a Submenu Menu Item, i want the item to perform func xyz when pressed, and I have created this NSMenuItem
class:
class itemClass: NSMenuItem {
func xyz(){
//function code
}
}
Then in the attributes inspector for the menu item i have assigned it the class itemClass. When i run the app the menu item is disabled despite the fact that is enabled in the attributes inspector.
Any help?
You don't need to subclass NSMenuItem to do so. NSMenuItem objects normally rely on the responder chain. You have to set your method in the attributes inspector of the first responder object like this:
Then you need to connect your menuItem to the firstResponder and select the method you just created. After that, follow this answers instructions to enable the menu item.