Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Created October 23, 2024 12:41
Show Gist options
  • Select an option

  • Save takoikatakotako/43657bbf56f285769263f0eb0f3539d3 to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/43657bbf56f285769263f0eb0f3539d3 to your computer and use it in GitHub Desktop.
SwiftUIでListにButtonを設定して異なる画面に遷移する
import SwiftUI
struct ContentView: View {
@State var pokemon: Pokemon?
var body: some View {
NavigationStack {
List {
Button {
pokemon = .snorlax
} label: {
Text("Snorlax")
}
Button {
pokemon = .slowpoke
} label: {
Text("Slowpoke")
}
Button {
pokemon = .eevee
} label: {
Text("Eevee")
}
}
.navigationDestination(item: $pokemon) { pokemon in
switch pokemon {
case .snorlax:
VStack {
Image(.snorlax)
Text("Snorlax")
}
case .slowpoke:
Text("Slowpoke")
case .eevee:
Image(.eevee)
}
}
}
}
}
import SwiftUI
enum Pokemon: Hashable {
case snorlax
case slowpoke
case eevee
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment