I populated a SwiftUI Picker dynamically. The Picker is working successfully. I want to trigger or listen picker changing event. Suppose I will print the value if an user select an item. My iOS deployment target is 14, I found that iOS has an inbuilt function onChange to detect this kind of listener. I used that modifier but not working. Here is my code:
var body: some View {
Picker( selection: $selectedStrength, label: Text("Status")) {
ForEach(courseList, id: \.self) { item in
Text(item.courseCode ?? "")
}
}
.onChange(of:selectedStrength, perform: { _ in
print("Value Changed!")
})
.pickerStyle(WheelPickerStyle())
}