Created
August 12, 2020 11:12
-
-
Save chriseidhof/a9b4c1220af9ce9143341d30bca983b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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