Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Created Feb 13, 2021
Embed
What would you like to do?
import SwiftUI
struct ContentView: View {
@State var selectedIndex = -1
var selection: String {
switch selectedIndex {
case 0: return "\u{2664}"
case 1: return "\u{2663}"
case 2: return "\u{2660}"
case 3: return "\u{2666}"
default: return ""
}
}
var body: some View {
VStack {
Text("Favourite card suit:")
Text(selection)
.font(.system(size: 200))
.focusable()
.padding()
.contextMenu {
Button("\u{2664} - Hearts") {selectedIndex = 0}
Button("\u{2663} - Clubs") {selectedIndex = 1}
Button("\u{2660} - Spades") {selectedIndex = 2}
Button("\u{2666} - Diamonds") {selectedIndex = 3}
}
Text("Long press to make a choice")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment