---
title: "willOpenMenu(_:with:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsview/willopenmenu(_:with:)"
---

# willOpenMenu(_:with:)

Called just before a contextual menu for a view is opened on screen.

## Declaration

```swift
func willOpenMenu(_ menu: NSMenu, with event: NSEvent)
```

## Parameters

- `menu`: The menu that will be opened.
- `event`: The event that caused the menu to open.

## Discussion

Discussion This method is called just before a contextual menu for a view is opened on screen. It provides an opportunity to make any desired changes to the visual state of the view. For example, a table view might select a row in response to the contextual menu being displayed.

## See Also

### Managing Contextual Menus

- [menu(for:)](appkit/nsview/menu(for:).md)
- [defaultMenu](appkit/nsview/defaultmenu.md)
- [didCloseMenu(_:with:)](appkit/nsview/didclosemenu(_:with:).md)
