Custom menu for Document based app

In my document-based app for macOS I am using storyboard. I create a custom menu and menu items in storyboard. The menu is there, but the menu item remains inactive (grey).

In order to activate the menu, one has to use NSWindowDelegate and walk the menu tree, to enable the menu items.

import Foundation
import Cocoa

class DocumentController: NSViewController, NSTextFieldDelegate {
    @IBOutlet var myOutlet: NSView!
    // ... code here ...
}

extension DocumentController: NSWindowDelegate {
    func windowDidBecomeMain(_ notification: Notification) {
        NSLog("windowDidBecomeMain - enable menu")
        if let customMenu = NSApp.mainMenu?.items[2].submenu {
            customMenu.item(at: 1)?.isEnabled = true
        }
    }
    func windowDidResignMain(_ notification: Notification) {
        NSLog("windowDidResignMain - disable menu")
    }
}

I added the outlet (myOutlet) in storyboard, but windowDidBecomeMain() does not get called?

Thanks for any help.

Custom menu for Document based app
 
 
Q