Im trying to get sort id which is come from my server . when user select sort in menu I should have selected id . But somehow when I selected sort its not triggered.Where do I make mistake ? when I change to selection to UUID then I can get uuıd for every selection but I should get their id which they are string that's why selection is string.
` @State private var selection = ""
@Binding var sortClicked : Bool
@ObservedObject var productListViewModel = ProductListViewModel()
@State var sortListArray : [ProductListSortAndFilterList]
var body : some View {
HStack(alignment: .center){
Spacer()
Picker(selection: $selection, label: SortView().frame(height:UIScreen.main.bounds.height * 0.050), content: {
ForEach(sortListArray,id:\.id) { item in
if item.id == "sort" {
ForEach(item.sortList ?? [],id:\.id) { data in
Text(data.name ?? "")
.tag(data.id)
}
.onReceive(Just(selection)) { (value) in
print(value)
}
}
}
})
.pickerStyle(MenuPickerStyle())
.padding()
.background(Color(.systemBackground).edgesIgnoringSafeArea(.all))
.cornerRadius(5)
```
` @State private var selection = ""
@Binding var sortClicked : Bool
@ObservedObject var productListViewModel = ProductListViewModel()
@State var sortListArray : [ProductListSortAndFilterList]
var body : some View {
HStack(alignment: .center){
Spacer()
Picker(selection: $selection, label: SortView().frame(height:UIScreen.main.bounds.height * 0.050), content: {
ForEach(sortListArray,id:\.id) { item in
if item.id == "sort" {
ForEach(item.sortList ?? [],id:\.id) { data in
Text(data.name ?? "")
.tag(data.id)
}
.onReceive(Just(selection)) { (value) in
print(value)
}
}
}
})
.pickerStyle(MenuPickerStyle())
.padding()
.background(Color(.systemBackground).edgesIgnoringSafeArea(.all))
.cornerRadius(5)
```