<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.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:7SwiftUI6ButtonVA2A4TextVRszrlE_4role6actionACyAEG10Foundation23LocalizedStringResourceV_AA0C4RoleVSgyyctcfc::OverloadGroup"
  },
  "title" : "init(_:role:action:)"
}
-->

# init(_:role:action:)

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

```
@preconcurrency @export(implementation) nonisolated init(_ titleResource: LocalizedStringResource, role: ButtonRole?, action: @escaping @MainActor () -> Void)
```

## Parameters

`titleResource`

Text resource 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

This initializer creates a [`Text`](/documentation/SwiftUI/Text) view on your behalf. See
[`Text`](/documentation/SwiftUI/Text) for more information about localizing strings.

---

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)