Enablemenuitems but for Swift?

I am building a macOS app menu programmatically (ie. no storyboard)
building the menu itself is fairly easy, and attaching code to each item works fine.

But what I cannot figure out, is how to detect that I clicked a MAIN item
[File] [Edit] [View] etc.
so that I can set the state of the items under that heading based on the status of the app at that time

any “action” I attach to those are ignored

override func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {