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

# validateToolbarItem(_:)

Determines whether to enable or disable the toolbar item.

```
@MainActor func validateToolbarItem(_ item: NSToolbarItem) -> Bool
```

## Discussion

If this method is implemented and returns <doc://com.apple.documentation/documentation/Swift/false>, [`NSToolbar`](/documentation/AppKit/NSToolbar) will disable `item`. Returning <doc://com.apple.documentation/documentation/Swift/true> causes `item` to be enabled.

[`NSToolbar`](/documentation/AppKit/NSToolbar) only calls this method for image items.

> Note:
> <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/validateToolbarItem:> is called very frequently, so it must be efficient.

If the receiver is the `target` for the actions of multiple toolbar items, it’s necessary to determine which toolbar item `item` refers to by testing the `itemIdentifier`.

```objc
-(BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem
{
    BOOL enable = NO;
    if ([[toolbarItem itemIdentifier] isEqual:SaveDocToolbarItemIdentifier]) {
        // We will return YES (enable the save item)
        // only when the document is dirty and needs saving
        enable = [self isDocumentEdited];
    } else if ([[toolbarItem itemIdentifier] isEqual:NSToolbarPrintItemIdentifier]) {
        // always enable print for this window
        enable = YES;
    }
    return enable;
}
```

## See Also

[`func validateVisibleItems()`](/documentation/AppKit/NSToolbar/validateVisibleItems())

Validates the toolbar’s visible items during a window update.

[`var action: Selector?`](/documentation/AppKit/NSToolbarItem/action)

The action method to call when someone clicks on the toolbar item.

[`var target: AnyObject?`](/documentation/AppKit/NSToolbarItem/target)

The object that defines the action method the toolbar item calls when clicked.

[`func validate()`](/documentation/AppKit/NSToolbarItem/validate())

Validates the toolbar item’s menu and its ability to perfrom its action.



---

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)