<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSToolbarDelegate/toolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSToolbarDelegate(im)toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:"
  },
  "title" : "toolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:)"
}
-->

# toolbar(_:itemForItemIdentifier:willBeInsertedIntoToolbar:)

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

```
@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

A new [`NSToolbarItem`](/documentation/AppKit/NSToolbarItem) object, or `nil` if no toolbar item is available for the specified identifier.

## Discussion

Use this method to create new [`NSToolbarItem`](/documentation/AppKit/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

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

Provide users quick access to your app’s features from a toolbar and corresponding Touch Bar.



---

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)