Getting SwiftUI macOS app to have fullscreen menu option.

Not sure why this has to be so obscure. But somehow adding the call into toggleFullscreen, even though this appDelegate doesn't have a window set, adds a menu item with the fn+F menu item. Posting this to save other pain. Plus the View menu doesn't even have a reference, and is empty otherwise. Pretty hard to polish something shippable with these unfixed outstanding flaws in the API.

 CommandGroup(after: .toolbar) {
                // must call through NSWindow
                Button("See Below") {
                    // Window isn't set in AppDelegate, so menu item is skipped.
                    // But add fn+F menu item into app.  Suo many stupid hacks.
                    appDelegate.window?.toggleFullScreen(nil)
                }
            }

Replies

The "Enter Fullscreen" menu item somehow disappears in some builds - could be Release builds. So not sure what is going on here.