How use Menu

Asked on 04/10/2025

1 search

To use menus in your app, you can leverage the new capabilities introduced in the WWDC sessions. Specifically, in the session titled "What’s new in AppKit," there are several enhancements related to menu usage:

  1. SwiftUI Menus in AppKit: You can now use SwiftUI menus within AppKit contexts using NSHostingMenu, a new NSMenu subclass. This allows you to share menu definitions between parts of your app that use AppKit and those that use SwiftUI. You can create your menu definition using a SwiftUI view and use it in any AppKit context that accepts an NSMenu. This is covered in the session What’s new in AppKit (06:21).

  2. Context Menu Positioning: In macOS Sequoia, you can use the keyboard to open a context menu for the currently focused UI element. The default shortcut is Control + Return, but it can be customized. The menu is positioned automatically over the view's bounds if your view has a value for the menu property. This is discussed in the session What’s new in AppKit (08:44).

  3. Menu Actions in UIKit: Menu actions provide all of an app's commands in the macOS menu bar and in the iPadOS and visionOS keyboard shortcut menus. iOS 18 makes menu actions more useful for iPhone-only apps. This is detailed in the session What’s new in UIKit (18:14).

These enhancements make it easier to integrate and manage menus across different Apple platforms, providing a more cohesive user experience.