Search code examples
cocoansmenuitem

What is the purpose of the NSMenuItem's tag attribute?


Can I use the item's tag attribute to store a special key/ID or is it meant for something else?

Example of intended use:

  - (void)awakeFromNib {

    [self.popup addItemWithTitle: [NSString stringWithFormat: @"dummy title" ]];
    [[self.popup lastItem] setTag: 1658 ];
  }

  - (IBAction)popupAction: (id)sender {

    [self someMethod: [sender selectedItem].tag];

  }

Solution

  • yeah the tag of all controls is free for your devious use, you may use different numbers for different items, or to identify them as a kind of item, it is up to you.