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

# touchBar(_:)

Sets the Touch Bar content to be shown in the Touch Bar when applicable.

## Declaration

```swift
nonisolated func touchBar<Content>(_ touchBar: TouchBar<Content>) -> some View where Content : View

```

## Parameters

- `touchBar`: A collection of views that the Touch Bar displays.

## Return Value

Return Value A view that contains the Touch Bar content.

## Discussion

Discussion Use touchBar(_:) to provide a static set of views that are displayed by the Touch Bar when appropriate, depending on whether the view has focus. The example below provides Touch Bar content in-line, that creates the content the Touch Bar displays: func selectHearts() {/* ... */ } func selectClubs() { /* ... */ } func selectSpades() { /* ... */ } func selectDiamonds() { /* ... */ }

TextField("TouchBar Demo", text: $placeholder)     .frame(maxWidth: .infinity, maxHeight: .infinity)     .focusable()     .touchBar {         Button("♥️ - Hearts", action: selectHearts)         Button("♣️ - Clubs", action: selectClubs)         Button("♠️ - Spades", action: selectSpades)         Button("♦️ - Diamonds", action: selectDiamonds)     }

## See Also

### Managing Touch Bar input

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