When entering data for a medication in my Health app I want the user to select the doctor prescribing the medication! I have a table of doctors that I can @Query to build an array. How do I allow the user to select the appropriate doctor using a SwiftUI Picker control.
The @Query is:
@Query(sort: \MedicalPersonnel.surname) var medicalPersonnel: [MedicalPersonnel]
The picker control is:
Picker("Prescribed By", selection: $prescribedBy) {
ForEach(medicalPersonnel) { mp in
Text("\(mp.surname)").tag(mp)
}
}
I varied the .tag component without success!
tag. See the answer I linked to.selection:argument in the Picker needs to be the same type as the tag