Contents

destructive

A role that indicates a destructive button.

Declaration

static let destructive: ButtonRole

Mentioned in

Discussion

Use this role for a button that deletes user data, or performs an irreversible operation. A destructive button signals by its appearance that the user should carefully consider whether to tap or click the button. For example, SwiftUI presents a destructive button that you add with the swipeActions(edge:allowsFullSwipe:content:) modifier using a red background:

List {
    ForEach(items) { item in
        Text(item.title)
            .swipeActions {
                Button(role: .destructive) { delete() } label: {
                    Label("Delete", systemImage: "trash")
                }
            }
    }
}
.navigationTitle("Shopping List")

[Image]

See Also

Getting button roles