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

# validateMenuItem(_:)

Implemented to override the default action of enabling or disabling a specific menu item.

```
@MainActor func validateMenuItem(_ menuItem: NSMenuItem) -> Bool
```

## Parameters

`menuItem`

An [`NSMenuItem`](/documentation/AppKit/NSMenuItem) object that represents the menu item.

## Return Value

<doc://com.apple.documentation/documentation/Swift/true> to enable `menuItem`, <doc://com.apple.documentation/documentation/Swift/false> to disable it.

## Discussion

The object implementing this method must be the target of `menuItem`. You can determine which menu item `menuItem` is by querying it for its tag or action.

The following example disables the menu item associated with the `nextRecord` action method when the selected line in a table view is the last one; conversely, it disables the menu item with `priorRecord` as its action method when the selected row is the first one in the table view. (The `countryOrRegionKeys` array contains names that appear in the table view.)

```objc
- (BOOL)validateMenuItem:(NSMenuItem *)item {
    int row = [tableView selectedRow];
    if ([item action] == @selector(nextRecord) &&
        (row == [countryOrRegionKeys indexOfObject:[countryOrRegionKeys lastObject]])) {
        return NO;
    }
    if ([item action] == @selector(priorRecord) && row == 0) {
        return NO;
    }
    return YES;
}
```

---

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)