HelloToYou
HelloToYou

Reputation: 345

How to get the main NSMenu in Swift?

I would like to get the main NSMenu in Swift for execution the following code NSMenu(title: "ApplicationName").autoenablesItems = false. I don't know what to insert as title, because it seems that it can't get a reference to it and disable autoenablesItems, because I can't set a MenuItem's enabled-Property.

Upvotes: 2

Views: 511

Answers (1)

Young suk
Young suk

Reputation: 1

Just a quick comment, hoping it helps someone else with the same question. The answer to this question is to add the main menu or menu items automatically created in the storyboard to appDelegate and create related code.

class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var saveMenuItem: NSMenuItem! // Can be added by dragging from the storyboard

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        // Insert code here to initialize your application
    }

    func applicationWillTerminate(_ aNotification: Notification) {
        // Insert code here to tear down your application
        
    }
}

Upvotes: 0

Related Questions