osx NSMenuItem Supporting default menu actions


Example

Menus act like all standard control items. They have an action which is the function to be called and a target which is the object to send the function to. If the target is set to an object then when a user selects a menu item it the action method will be sent to the target object. If the menu item has an action, but not a target then the target will be dynamically selected from the first object from the following that responds to the action:

  1. The first responder
  2. The view hierarchy
  3. Window
  4. Window controller
  5. NSApplication
  6. NSApplication.delegate
  7. NSApplication.nextResponder

Implementing the default Open (⌘O) menu item can be accomplished by implementing the openDocument method on any object in the above list.

- (IBAction)openDocument:(id)sender {

}