Skip to content

Instantly share code, notes, and snippets.

@christianselig
Created February 6, 2024 20:59
Show Gist options
  • Save christianselig/305d3362d83eaea4fecf214fb4054c9d to your computer and use it in GitHub Desktop.
Save christianselig/305d3362d83eaea4fecf214fb4054c9d to your computer and use it in GitHub Desktop.
import SwiftUI
struct ContentView: View {
var viewModel = CoolViewModel()
var body: some View {
VStack {
Menu {
Picker("Ice Cream", selection: $viewModel.selectedIceCream) {
ForEach(viewModel.iceCreams) { iceCream in
Text(iceCream)
.tag(iceCream)
}
}
} label: {
Text("Choose")
}
}
}
}
@Observable
class CoolViewModel {
var selectedIceCream = "chocolate"
var iceCreams: [String] = ["chocolate", "vanilla", "strawberry"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment