<!--
{
  "availability" : [
    "macOS: 10.15.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/touchBarItemPresence(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE20touchBarItemPresenceyQrAA05TouchefG0OF"
  },
  "title" : "touchBarItemPresence(_:)"
}
-->

# touchBarItemPresence(_:)

Sets the behavior of the user-customized view.

```
nonisolated func touchBarItemPresence(_ presence: TouchBarItemPresence) -> some View
```

## Parameters

`presence`

One of the allowed [`TouchBarItemPresence`](/documentation/SwiftUI/TouchBarItemPresence)
descriptions.

## Return Value

A trait that describes the behavior for this Touch Bar
view.

## Discussion

Use `touchBarItemPresence(_:)` to define the visibility requirements of
a particular Touch Bar view during customization by the user.

Touch Bar views may be:

- `.required`: not allowed to be removed by the user.
- `.default`: shown by default prior to user customization, but
  removable.
- `.optional`: not visible by default, but can be added through the
  customization palette.

Each [`TouchBarItemPresence`](/documentation/SwiftUI/TouchBarItemPresence) must be initialized with a string that is
a globally unique identifier for this item.

In the example below, all of the Touch Bar items are visible in the
Touch Bar by default, except for the “Clubs” item. It’s set to
`.optional` but is configurable by the user:

```
TextField("TouchBar Demo", text: $placeholder)
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .focusable()
    .touchBar {
        Button("♥️", action: selectHearts)
            .touchBarItemPresence(.required("heartsKey"))
        Button("♣️", action: selectClubs)
            .touchBarItemPresence(.optional("clubsKey"))
        Button("♠️", action: selectSpades)
            .touchBarItemPresence(.required("spadesKey"))
        Button("♦️", action: selectDiamonds)
            .touchBarItemPresence(.required("diamondsKey"))
}
```

![A view showing the configuration of the Touch Bar with required and](images/com.apple.SwiftUI/SwiftUI-touchBarItemPresence@2x.png)

---

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)