Here's the result of a blank app from Xcode:
https://imgur.com/a/1hMmwbO
now there's only 3 items in the storyboard configuration:
https://imgur.com/a/iGWWQE7
So I try to replicate that in code (some of this reproducer was generated by ChatGPT however the same issue I'm descrbing has been hit when using Python to objc bridges to construct the GUI) by specifying these 3 actions appropriately and see if the rest pops up. The code below changes the activation policy so that when I run ./a.out from the terminal it doesn't show as a window of Terminal but a separate app
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@end
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
// Build main menu
NSMenu *mainMenu = [[NSMenu alloc] initWithTitle:@"MainMenu"];
// --- App menu with Quit ---
NSMenuItem *appMenuItem = [[NSMenuItem alloc] init];
NSMenu *appMenu = [[NSMenu alloc] initWithTitle:@"App"];
NSMenuItem *quitItem = [[NSMenuItem alloc] initWithTitle:@"Quit"
action:@selector(terminate:)
keyEquivalent:@"q"];
[appMenu addItem:quitItem];
[appMenuItem setSubmenu:appMenu];
[mainMenu addItem:appMenuItem];
// --- Window menu with only Minimize, Zoom, Bring All to Front ---
NSMenuItem *windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:NULL keyEquivalent:@""];
NSMenu *windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
[windowMenu addItem:[[NSMenuItem alloc] initWithTitle:@"Minimize"
action:@selector(performMiniaturize:)
keyEquivalent:@"m"]];
[windowMenu addItem:[[NSMenuItem alloc] initWithTitle:@"Zoom"
action:@selector(performZoom:)
keyEquivalent:@""]];
[windowMenu addItem:[NSMenuItem separatorItem]];
[windowMenu addItem:[[NSMenuItem alloc] initWithTitle:@"Bring All to Front"
action:@selector(arrangeInFront:)
keyEquivalent:@""]];
[windowMenuItem setSubmenu:windowMenu];
[mainMenu addItem:windowMenuItem];
[NSApp setMainMenu:mainMenu];
// Optional demo window (remove if you want zero windows)
NSWindow *w = [[NSWindow alloc] initWithContentRect:NSMakeRect(200,200,400,200)
styleMask:(NSWindowStyleMaskTitled |
NSWindowStyleMaskClosable |
NSWindowStyleMaskResizable |
NSWindowStyleMaskMiniaturizable)
backing:NSBackingStoreBuffered
defer:NO];
[w setTitle:@"Demo"];
[w makeKeyAndOrderFront:nil];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
}
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return YES;
}
@end
int main(int argc, const char * argv[]) {
@autoreleasepool {
AppDelegate *delegate = [AppDelegate new];
[NSApplication sharedApplication];
[NSApp setDelegate:delegate];
return NSApplicationMain(argc, argv);
}
}
Now, I only see 3 items that's literally specified
https://imgur.com/a/LylRsaJ
So, what allows interface builder to auto-add these extra items as opposed by creating it in code? Is there something in this reproducer of the Window menu that is missing that needs to make it happen programatically?
Thanks!
All tests done on macOS Tahoe
Topic:
UI Frameworks
SubTopic:
AppKit