<!--
{
  "availability" : [
    "macOS: 10.0.0 - 11.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "ObjectiveC",
  "identifier" : "/documentation/ObjectiveC/NSObject-swift.class/validateToolbarItem:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Objective-C Runtime"
    ],
    "preciseIdentifier" : "c:objc(cs)NSObject(im)validateToolbarItem:"
  },
  "title" : "validateToolbarItem:"
}
-->

# validateToolbarItem:

If this method is implemented and returns `false`, NSToolbar will disable `theItem`; returning `true` causes `theItem` to be enabled.

```
- (BOOL) validateToolbarItem:(NSToolbarItem *) item;
```

## Discussion

NSToolbar only calls this method for image items.

> Note:
> ``doc://com.apple.objectivec/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 `theItem` 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

  <doc://com.apple.documentation/documentation/AppKit/NSToolbar/validateVisibleItems()>

  <doc://com.apple.documentation/documentation/AppKit/NSToolbarItem/action>

  <doc://com.apple.documentation/documentation/AppKit/NSToolbarItem/target>

  [Toolbar Programming Topics for Cocoa](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Toolbars/Toolbars.html#//apple_ref/doc/uid/10000109i)

  <doc://com.apple.documentation/documentation/AppKit/NSToolbarItem/validate()>



---

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)