Contents

toolbar(_:itemIdentifier:canBeInsertedAt:)

Asks the delegate for a Boolean value that indicates whether the toolbar can place the item at the specified position.

Declaration

@MainActor optional func toolbar(_ toolbar: NSToolbar, itemIdentifier: NSToolbarItem.Identifier, canBeInsertedAt index: Int) -> Bool

Parameters

  • toolbar:

    The toolbar that contains the items.

  • itemIdentifier:

    The identifier of the toolbar item to insert at the specified index.

  • index:

    The proposed index at which to place the item. If the toolbar is removing the item, this value is Nsnotfound 4qp9h.

Return Value

true to allow the toolbar to place the item at the specified location, or false to prevent the toolbar from placing the item in that location.

Discussion

Implement this method to control the placement of items in the toolbar. During a drag operation, the toolbar calls this method to determine if the specified index is an acceptable location for the item. Return a Boolean value that indicates whether the new posiition is acceptable.

Don’t use the index parameter to determine the final location of the toolbar item. During a drag operation, the toolbar can call this method multiple times, so the index value can change later.

See Also

Configuring the behavior of items