0

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!

4
  • How is prescribedBy declared? Maybe your issue is similar to this question Commented Jul 7, 2024 at 19:55
  • PrescribedBy is a defined in the table model as: var PrescribedBy: String = "" Commented Jul 8, 2024 at 14:52
  • I don't know what you mean by table model but it needs to be the same type as the tag. See the answer I linked to. Commented Jul 8, 2024 at 15:22
  • To clarify, the variable you use for the selection: argument in the Picker needs to be the same type as the tag Commented Jul 8, 2024 at 15:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.