I am constructing a app and I’ve a Picker
wheel and I discovered you should utilize .onChange
to detect a change within the picker.
So I ended up with this code:
struct ContentView: View {
let languages = ["English", "Chineese", "French", "Spanish"]
@State personal var language = "English"
var physique: some View {
Picker("Language", choice: $language) {
ForEach(languages, id: .self) {
Textual content($0)
}
}
.pickerStyle(.wheel)
.onChange(of: language) { newValue in
print("Labored!")
}
}
}
It really works as anticipated the when first constructing and launching the app and prints out “Labored!” correctly. However closing the app and reopening it, I can nonetheless use the picker, however once I transfer the picker it doesn’t print “Labored!”. I could not discover out why or discover something on-line about it, so I am actually confused.
Here is a GIF exhibiting what’s taking place: