<!--
{
  "availability" : [
    "macOS: 14.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "VisionKit",
  "identifier" : "/documentation/VisionKit/ImageAnalysisOverlayViewDelegate/overlayView(_:updatedMenuFor:for:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "VisionKit"
    ],
    "preciseIdentifier" : "s:9VisionKit32ImageAnalysisOverlayViewDelegateP07overlayF0_14updatedMenuFor3for2atSo6NSMenuCAA0cdeF0C_AISo7NSEventCSo7CGPointVtF"
  },
  "title" : "overlayView(_:updatedMenuFor:for:at:)"
}
-->

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

Notifies your app before the framework presents a context menu.

```
@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

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”.

```swift
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`](/documentation/VisionKit/ImageAnalysisOverlayView/MenuTag/recommendedAppItems) menu tag, such as in the following code:

```swift
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 <doc://com.apple.documentation/documentation/AppKit/NSMenuDelegate> callbacks for VisionKit-specific menu items.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)