Showing and hiding alternate menu items in Swift on macOS

For v2 of Rest I wanted to have menu items that show alternate titles and actions when the user holds Option.

After going through a couple of answers on StackOverflow and discussions they linked to, I found out it’s now way easier than ever to achieve it. There’s no need to run custom loops or set unnecessary keyboard shortcuts at all.

So here’s how you do it.

First, in your Storyboard/XIB, create all your menu items. Every second menu item should be set as alternate. For example, if you’ve created the following menu items:

Then, select all your alternate items, and:

  1. Mark them as Alternate
  2. Set ⌥ (Option key) as a Key Equivalent.

They also need to be connected to the same action.

And that’s it. Here it is in action.

0:00
/
Video size: 175kb