---
title: "touchBar(content:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/touchbar(content:)"
---

# touchBar(content:)

Sets the content that the Touch Bar displays.

## Declaration

```swift
nonisolated func touchBar<Content>(@ContentBuilder content: () -> Content) -> some View where Content : View

```

## Parameters

- `content`: A collection of views to be displayed by the Touch Bar.

## Return Value

Return Value A view that contains the Touch Bar content.

## Discussion

Discussion Use touchBar(_:) when you need to dynamically construct items to show in the Touch Bar. The content is displayed by the Touch Bar when appropriate, depending on focus. In the example below, four buttons are added to a Touch Bar content struct and then added to the Touch Bar: let touchBarItems = TouchBar(id: "myBarItems") {     Button("♣️", action: {})     Button("♥️", action: {})     Button("♠️", action: {})     Button("♦️", action: {}) }

TextField("TouchBar Demo", text: $placeholder)     .frame(maxWidth: .infinity, maxHeight: .infinity)     .focusable()     .touchBar(touchBarItems)

## See Also

### Managing Touch Bar input

- [touchBar(_:)](swiftui/view/touchbar(_:).md)
- [touchBarItemPrincipal(_:)](swiftui/view/touchbaritemprincipal(_:).md)
- [touchBarCustomizationLabel(_:)](swiftui/view/touchbarcustomizationlabel(_:).md)
- [touchBarItemPresence(_:)](swiftui/view/touchbaritempresence(_:).md)
- [TouchBar](swiftui/touchbar.md)
- [TouchBarItemPresence](swiftui/touchbaritempresence.md)
