Instead of using swipe actions, we can present them in a context menu. In iOS, users typically long-press a list row to open a context menu. As with swipe actions, SwiftUI makes it easy to create a context menu.
In iOS, a pop-up menu is typically activated by a long press. A context menu consists of a collection of buttons, each with its own action, text, and icon.
In the following example, we create a context menu with the contextMenu modifier:
Text("Options")
.contextMenu {
Button {
print("Make Favorite")
} label: {
Label("Make Favorite", systemImage: "heart")
}
Button {
print("Share")
} label: {
Label("Share Location", systemImage: "square.and.arrow.up")
}
}
In Xcode the result would be the following:
