Skip to content

Instantly share code, notes, and snippets.

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

  • Save takoikatakotako/62204695cace4a478a097d8d4445a2f5 to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/62204695cace4a478a097d8d4445a2f5 to your computer and use it in GitHub Desktop.
画面遷移時に値を渡す
import SwiftUI
struct ContentView: View {
let fruits = ["Apple", "Banana", "Orange", "Grape", "Cherry", "Peach"]
var body: some View {
NavigationView {
List(fruits, id: \.self) { fruit in
NavigationLink(destination: SecondView(fruit: fruit)) {
Text(fruit)
}
}
}
}
}
#Preview {
ContentView()
}
import SwiftUI
struct SecondView: View {
let fruit: String
var body: some View {
Text(fruit)
}
}
#Preview {
SecondView(fruit: "Apple")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment