---
title: "toolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstoolbardelegate/toolbar(_:itemforitemidentifier:willbeinsertedintotoolbar:)"
---

# toolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:)

Asks the delegate for the toolbar item associated with the specified identifier.

## Declaration

```swift
@MainActor optional func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem?
```

## Parameters

- `toolbar`: The toolbar for which the item is being requested.
- `itemIdentifier`: The identifier for the requested item.
- `flag`: doc://com.apple.documentation/documentation/Swift/true if the toolbar will insert the item immediately. If this parameter is doc://com.apple.documentation/documentation/Swift/false, provide a canonical representation for the item. For example, provide a version of the item suitable for display in the toolbar customization sheet.

## Return Value

Return Value A new NSToolbarItem object, or nil if no toolbar item is available for the specified identifier.

## Discussion

Discussion Use this method to create new NSToolbarItem objects when the toolbar asks for them. If your toolbar item uses a custom view, make sure that view is fully configured before you return the item. The toolbar becomes the owner of the returned item, but can display the item either in the toolbar or the customization palette. Don’t recycle toolbar items; always provide a new instance, even if the toolbar previously asked for an item with the same identifier. important: Even though this is an optional method, you must implement it if you create the toolbar programatically.

## See Also

### Related Documentation

- [Integrating a Toolbar and Touch Bar into Your App](appkit/integrating-a-toolbar-and-touch-bar-into-your-app.md)

### Adding and removing items

- [toolbarWillAddItem(_:)](appkit/nstoolbardelegate/toolbarwilladditem(_:).md)
- [toolbarDidRemoveItem(_:)](appkit/nstoolbardelegate/toolbardidremoveitem(_:).md)
- [NSToolbar.Identifier](appkit/nstoolbar/identifier-swift.typealias.md)
