Custom menu actions

I've added a custom menu "Statistics" to my app menu. I know the actions for its items can be placed in the AppDelegate file. But if possible I'd like to put these actions in a separate file, to simplify things. Can I add a new file to my project that will let me connect my custom menu items to the actions defined within it?

Replies

I put most of the menu Actions in AppController


A simple thing to do is to have the IBAction just call the function that you define in the other file.


    @IBAction func someFunction(_ sender: NSMenuItem) {
          someFunction()          // Defined where you want
}

What class does AppController inherit from?

Inherits from NSObject


class AppController: NSObject {

}


In AppDelegate, create

@IBOutlet weak var appController: AppController!

connected to an ObjectController in MainMenu.xib


To call

appController.someMethod()

Did this solve your problem ?


Note: one of your posts has been moved to Core OS / Files and Storage. Have a look to see if solution worked.