Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Created August 12, 2020 11:12
Show Gist options
  • Save chriseidhof/a9b4c1220af9ce9143341d30bca983b5 to your computer and use it in GitHub Desktop.
Save chriseidhof/a9b4c1220af9ce9143341d30bca983b5 to your computer and use it in GitHub Desktop.
import SwiftUI
let items = ["Basic", "Advanced", "Ultra"]
struct ContentView: View {
@State var value: Int = 0
var body: some View {
VStack {
Picker(selection: $value, label: Text("Mode:")) {
ForEach(0..<items.count) { i in
Text(items[i])
}
}
Picker(selection: $value, label: Text("Mode:")) {
ForEach(items.indices) { i in
Text(items[i])
}
}
Picker(selection: $value, label: Text("Mode:")) {
ForEach(items, id: \.self) { item in
Text(item).tag(items.firstIndex(of: item)!)
}
}
Picker(selection: $value, label: Text("Mode:")) {
Text("Basic").tag(0)
Text("Advanced").tag(1)
Text("Ultra").tag(2)
}
Text("\(value) - \(items[value])")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment