While your solution works for your problem, this isn't just a problem with menu:
It seems NSToolbarItem(itemIdentifier:, barButtonItem:) only works if you are using a #selector for your UIBarButtonItem. If you use primaryAction instead the button does nothing.