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

# touchBar(_:)

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

```
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

A view that contains the Touch Bar content.

## Discussion

Use [`touchBar(_:)`](/documentation/SwiftUI/View/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)
    }
```

![A Touch Bar that shows content you create by using a static collection](images/com.apple.SwiftUI/SwiftUI-touchbar-static@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)