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

# touchBar(content:)

Sets the content that the Touch Bar displays.

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

A view that contains the Touch Bar content.

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

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