'NSMenuItem keyEquivalent not calling selector within submenu

I have an array and create a NSMenuItem for each array item. Additionally the first 9 items get a keyboard shortcut assigned (1-9). Clicking the item calls the selector like usual, but pressing the shortcut doesn't.

The sample code below is a subclass of NSMenu, used as a submenu

let itemArray: Array<String> = ["Apples", "Bananas", "Oranges"]
var itemIndex: UInt = 1
                        
for item in itemArray {
    let menuItem = NSMenuItem()
    menuItem.target = self
    menuItem.title = item
    menuItem.action = #selector(self.doSomething)
                            
    if itemIndex <= 9 {
        menuItem.keyEquivalent = "\(itemIndex)"
        itemIndex += 1
    }
                            
    self.addItem(menuItem)
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source