---
title: "overlayView(_:updatedMenuFor:for:at:)"
framework: visionkit
role: symbol
role_heading: Instance Method
path: "visionkit/imageanalysisoverlayviewdelegate/overlayview(_:updatedmenufor:for:at:)"
---

# overlayView(_:updatedMenuFor:for:at:)

Notifies your app before the framework presents a context menu.

## Declaration

```swift
@MainActor func overlayView(_ overlayView: ImageAnalysisOverlayView, updatedMenuFor menu: NSMenu, for event: NSEvent, at point: CGPoint) -> NSMenu
```

## Parameters

- `overlayView`: The associated overlay view for the updated menu.
- `menu`: The menu that appears.
- `event`: The event associated with this menu.
- `point`: The original location of the event for the menu.

## Discussion

Discussion This callback enables your app to add custom context menu items or manage the framework-provided content menu items. For example, the following implementation changes the title of the framework-provided copySubject menu item from “Copy” to “Copy and remove background”. func overlayView(_ overlayView: ImageAnalysisOverlayView, updateMenu menu: NSMenu, forEvent: NSEvent, atPoint point: CGPoint) -> NSMenu {

let copySubjectItem = menu.item(withTag:ImageAnalysisOverlayView.MenuTag.copySubject)     copySubjectItem.title = "Copy and remove background"

return menu } The menu items don’t persist. However, your app can alter menu items and share them across different menus within the same menu session. To add items to a menu, access  the recommended index for insertion by using the recommendedAppItems menu tag, such as in the following code: func overlayView(_ overlayView: ImageAnalysisOverlayView, updateMenu menu: NSMenu, forEvent: NSEvent, atPoint point: CGPoint) -> NSMenu {

let item = NSMenuItem()     let tag = ImageAnalysisOverlayView.MenuTag.recommendedAppItems     let index = menu.indexOfItem(withTag:tag)     menu.insertItem(item, at: index)

return menu } note: The framework is the delegate for the returned menu item. The framework continues to support NSMenuDelegate callbacks for VisionKit-specific menu items.

## See Also

### Responding to key and menu events

- [overlayView(_:shouldHandleKeyDownEvent:)](visionkit/imageanalysisoverlayviewdelegate/overlayview(_:shouldhandlekeydownevent:).md)
- [overlayView(_:shouldShowMenuForEvent:atPoint:)](visionkit/imageanalysisoverlayviewdelegate/overlayview(_:shouldshowmenuforevent:atpoint:).md)
- [overlayView(_:menu:willHighlight:)](visionkit/imageanalysisoverlayviewdelegate/overlayview(_:menu:willhighlight:).md)
- [overlayView(_:willOpen:)](visionkit/imageanalysisoverlayviewdelegate/overlayview(_:willopen:).md)
- [overlayView(_:didClose:)](visionkit/imageanalysisoverlayviewdelegate/overlayview(_:didclose:).md)
- [overlayView(_:needsUpdate:)](visionkit/imageanalysisoverlayviewdelegate/overlayview(_:needsupdate:).md)
