<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/Button/init(role:action:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI6ButtonVA2A07DefaultC5LabelVRszrlE4role6actionACyAEGAA0C4RoleV_yyctcfc"
  },
  "title" : "init(role:action:)"
}
-->

# init(role:action:)

Creates a button that displays a default label.

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

For example, the following view would display a button
with a ‘x’ symbol in the toolbar.

```swift
struct NewContactSheet: View {
    var body: some View {
        NavigationStack {
            NewContactEditor()
                .toolbar {
                    Button(role: .cancel) {
                        dismissView()
                    }
                }
        }
    }
}
```

---

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)