<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSMenuDelegate/menu(_:update:at:shouldCancel:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSMenuDelegate(im)menu:updateItem:atIndex:shouldCancel:"
  },
  "title" : "menu(_:update:at:shouldCancel:)"
}
-->

# menu(_:update:at:shouldCancel:)

Invoked to let the delegate update a menu item before it is displayed.

```
@MainActor optional func menu(_ menu: NSMenu, update item: NSMenuItem, at index: Int, shouldCancel: Bool) -> Bool
```

## Parameters

`menu`

The menu object that owns `item`.

`item`

The menu-item object that may be updated.

`index`

The integer index of the menu item.

`shouldCancel`

Set to <doc://com.apple.documentation/documentation/Swift/true> if, due to some user action, the menu no longer needs to be displayed before all the menu items have been updated. You can ignore this flag, return <doc://com.apple.documentation/documentation/Swift/true>, and continue; or you can save your work (to save time the next time your delegate is called) and return <doc://com.apple.documentation/documentation/Swift/false> to stop the updating.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> to continue the process. If you return <doc://com.apple.documentation/documentation/Swift/false>, your [`menu(_:update:at:shouldCancel:)`](/documentation/AppKit/NSMenuDelegate/menu(_:update:at:shouldCancel:)) is not called again. In that case, it’s your responsibility to trim any extra items from the menu.

## Discussion

If your [`numberOfItems(in:)`](/documentation/AppKit/NSMenuDelegate/numberOfItems(in:)) delegate method returns a positive value, then your [`menu(_:update:at:shouldCancel:)`](/documentation/AppKit/NSMenuDelegate/menu(_:update:at:shouldCancel:)) method is called for each item in the menu. You can then update the menu title, image, and so forth for each menu item.

---

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)