Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Created October 24, 2024 01:55
Show Gist options
  • Select an option

  • Save takoikatakotako/7e0d7dd8182a7178ba4cd22f0b67ca30 to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/7e0d7dd8182a7178ba4cd22f0b67ca30 to your computer and use it in GitHub Desktop.
Pickerを表示する
import SwiftUI
struct ContentView: View {
let pokemons = ["Snorlax", "Pikachu", "Slowpoke", "Meowth"]
@State var selectedPokemon = 0
var body: some View {
Picker("Pokemon", selection: $selectedPokemon) {
ForEach(pokemons, id: \.self) { pokemon in
Text(pokemon)
}
}
.pickerStyle(WheelPickerStyle())
.onReceive([selectedPokemon].publisher.first()) { value in
print("SelectedPokemon: \(value)")
print(pokemons[value])
}
}
}
#Preview {
ContentView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment