---
title: "validateToolbarItem(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstoolbaritemvalidation/validatetoolbaritem(_:)"
---

# validateToolbarItem(_:)

Determines whether to enable or disable the toolbar item.

## Declaration

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

## Discussion

Discussion If this method is implemented and returns false, NSToolbar will disable item. Returning true causes item to be enabled. NSToolbar only calls this method for image items. note: 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. -(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

### Related Documentation

- [validateVisibleItems()](appkit/nstoolbar/validatevisibleitems().md)
- [action](appkit/nstoolbaritem/action.md)
- [target](appkit/nstoolbaritem/target.md)
- [validate()](appkit/nstoolbaritem/validate().md)
