Contents

item(forIdentifier:)

Returns the Touch Bar item that corresponds to a given identifier.

Declaration

func item(forIdentifier identifier: NSTouchBarItem.Identifier) -> NSTouchBarItem?

Return Value

A Touch Bar item if one exists for the given identifier; otherwise, returns nil.

Discussion

The system returns items (instances of the NSTouchBarItem class) as it finds them, according to the following search order, listed here from first-searched to last-searched:

  1. Items in the bar’s private array, which are reflected in the value of the itemIdentifiers array.

  2. Items in the templateItems array.

  3. Items returned from the bar delegate’s touchBar(_:makeItemForIdentifier:) method.

Your app never needs to instantiate spacing or proxy items because these are created by the system directly, according to their identifiers, as shown in the table below.

Constant

Resulting item

Fixedspacesmall

small space

Fixedspacelarge

large space

Flexiblespace

flexible space

Otheritemsproxy

proxy placeholder

For more on the proxy placeholder, see Composition and nesting.

See Also

Observing bar status