title: Can't Load SwiftUI Picker Choice from Core Data and Display as Selection
body: <p>I have a <code>SwiftUI</code> app that persists data in <code>CoreData</code>. I want to have a Picker where
  the user can choose an item (from one entity) and then store that information in
  another entity to be displayed as the Picker selection.</p>
  
  <p>I have an Entity named Patient where data is added by the user. I have an Entity
  named Clinic that is a list of objects created by the user. The purpose is to use
  the picker to rapidly add information without repeatedly typing the items for each
  Patient record.</p>
  
  <p>In <code>Swift</code>, I did this by attaching a UIPicker to a TextField. That worked fine. I have
  not been able to do the equivalent in SwiftUI. I can make the creation and population
  of the picker data and I successfully save changes to the Patient entity, but I have
  not been able to load the Patient Clinic data into the picker as the default when the
  Detail View is loaded.</p>
  
  <p><strong>This piece of the app is equivalent to the master/detail style. The DetailView is:</strong></p>
  
  <pre><code>struct DetailView: View {
  
      @Environment(\.managedObjectContext) var managedObjectContext
      @Environment(\.presentationMode) var presentationMode
      @FetchRequest(fetchRequest: Clinic.getAllClinics()) var clinics: FetchedResults&lt;Clinic&gt;
      @State private var selectClinicItem: Int = 0
      var patient: Patient
  
      @State private var updatedFirstName: String = "No First Name"
      @State private var updatedLastName: String = "No Last Name"
      @State private var updatedClinic: String = "Clinic Not Chosen"
      @State private var chosenClinicUUID: UUID = UUID()
  
      var body: some View {
  
          ScrollView {
              Group {//top group
                  VStack {
                      MyDataCell(tfData: $updatedFirstName, passedInLabel: "First Name", patient: patient, patientAttribute: patient.firstName ?? "No First")
                  }//Top VStack - 8 views
              }//top Group
  
              Group {//second group
                  Form {
                      Picker(selection: self.$chosenClinicUUID, label: Text("Choose Clinic")) {
                          ForEach(clinics) { c in
                              Text("\(c.name ?? "no name")")
                          }
                      }
                      .frame(width:320, height: 30)
                  }//Form
                  .frame(width:350, height: 200)
                  .clipShape(RoundedRectangle(cornerRadius: 12))
                  .overlay(RoundedRectangle(cornerRadius: 12)
                  .stroke(Color.gray, lineWidth: 2))
                  .padding(.leading, 12)
                  .padding(.top, 20)
                  .padding(.bottom, 20)
              }//second Group
  
          }//scroll or top level Form
  
              .modifier(AdaptsToSoftwareKeyboard())
              .navigationBarTitle("View and Edit", displayMode: .inline)
              .navigationBarItems(trailing: Button(action: {
  
                  self.patient.firstName = self.updatedFirstName
                  self.patient.lastName = self.updatedLastName
                  self.patient.clinicName = self.updatedClinic
                  self.patient.clinicID = self.chosenClinicUUID
  
                  let n = self.clinics.filter { $0.id == self.patient.clinicID }
  
                  if n.count &gt; 0 {
                      self.patient.clinicName = n[0].name
                  }
  
                  do {
                      try self.managedObjectContext.save()
                  } catch {
                      print(error)
                  }
  
                  self.updatedFirstName = ""
                  self.updatedLastName = ""
                  self.updatedClinic = ""
  
                  self.presentationMode.wrappedValue.dismiss()
  
              }) {
                  Text("Save")
              })
  
      }//body
  }
  </code></pre>
  
  <p><strong>And for reference, the Patient class:</strong></p>
  
  <pre><code>public class Patient : NSManagedObject, Identifiable {
      @NSManaged public var id: UUID
      @NSManaged public var firstName: String?
      @NSManaged public var lastName: String?
      @NSManaged public var clinicName: String?
      @NSManaged public var clinicID: UUID
  }
  
  extension Patient {
      static func getAllPatients() -&gt; NSFetchRequest&lt;Patient&gt; {
          let request: NSFetchRequest&lt;Patient&gt; = Patient.fetchRequest() as! NSFetchRequest&lt;Patient&gt;
          let sortDescriptor = NSSortDescriptor(key: "lastName", ascending: true)
          request.sortDescriptors = [sortDescriptor]
          return request
      }
  }
  </code></pre>
  
  <p><strong>The Clinic class:</strong></p>
  
  <pre><code>public class Clinic : NSManagedObject, Identifiable {
      @NSManaged public var id: UUID
      @NSManaged public var name: String?
      @NSManaged public var comment: String?
      @NSManaged public var isShown: Bool
  }
  
  extension Clinic {
      static func getAllClinics() -&gt; NSFetchRequest&lt;Clinic&gt; {
          let request: NSFetchRequest&lt;Clinic&gt; = Clinic.fetchRequest() as! NSFetchRequest&lt;Clinic&gt;
          let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
          request.sortDescriptors = [sortDescriptor]
          return request
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/cCXnp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cCXnp.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/UU0O5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UU0O5.png" alt="enter image description here"></a></p>
  
  <p><strong>Any guidance would be appreciated. Xcode Version 11.2.1 (11B500)</strong></p>