---
title: "init(role:action:)"
framework: swiftui
role: symbol
role_heading: Initializer
path: "swiftui/button/init(role:action:)"
---

# init(role:action:)

Creates a button that displays a default label.

## Declaration

```swift
@preconcurrency nonisolated init(role: ButtonRole, action: @escaping @MainActor () -> Void)
```

## Parameters

- `role`: A semantic role describing the button.
- `action`: The action to perform when the user triggers the button.

## Discussion

Discussion For example, the following view would display a button with a ‘x’ symbol in the toolbar. struct NewContactSheet: View {     var body: some View {         NavigationStack {             NewContactEditor()                 .toolbar {                     Button(role: .cancel) {                         dismissView()                     }                 }         }     } }
