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

# init(_:role:action:)

Creates a button with a specified role that generates its label from a localized string key.

## Declaration

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

## Parameters

- `titleKey`: The key for the button’s localized title, that describes the purpose of the button’s action.
- `role`: An optional semantic role describing the button. A value of nil means that the button doesn’t have an assigned role.
- `action`: The action to perform when the user triggers the button.

## Discussion

Discussion This initializer creates a Text view on your behalf, and treats the localized key similar to init(_:tableName:bundle:comment:). See Text for more information about localizing strings.

## See Also

### Creating a button with a role

- [init(role:action:label:)](swiftui/button/init(role:action:label:).md)
- [init(_:image:role:action:)](swiftui/button/init(_:image:role:action:).md)
- [init(_:systemImage:role:action:)](swiftui/button/init(_:systemimage:role:action:).md)
