This example shows that it does print on the first selection:
import SwiftUI
struct ContentView: View {
@State var fruitName: String = "none"
var body: some View {
VStack {
Menu {
PickFruit(fruitName: $fruitName)
} label: {Text("Select A Fruit")}
Text(fruitName)
}
.onChange(of: fruitName) { [fruitName] newValue in // move onchange to here
print(newValue)
print(fruitName)
}
}
}
struct PickFruit: View {
let myFruits: [String] = ["Apple","Banana","Grape","Peach"]
@Binding var fruitName: String
var body: some View {
VStack {
Text(fruitName)
Picker("Select", selection: $fruitName) {
ForEach(myFruits, id: \.self) { myFruits in
Text(myFruits)
}
}
}
}
}