SwiftData Picker

In using a Picker with SwiftData I am having trouble in obtaining the $selectedPicker value.
For displaying the value with Text(“(selectedCatagory)”) a long alfa-numeric string is given .
This can be seen on the screen shot behind the drop down list
The associated code is
List {
Picker(“Select catagory”,selection: $selectedCatagory) {
ForEach(catagories) { catagory in
Text(catagory.name)
.tag(Optional(catagory))
.font(.caption)
}
}
}


Any advice is appreciated.
Joel

Why have you specified Optional in the .tag?

Your .tag modifier should be

.tag(catagory.name)

Thanks Chris , I was getting an error without the .tag and Optional was the only example online I could find that got rid of the compiler error. Of course your recommendation works !

1 Like