title: SwiftUI FetchRequest Order Output in Picker
body: <p>I have a json I am fetching from a remote server that contains a list of countries (and ID, the country name, and the country abbreviation). I am populating a picker with these values via a ForEach.</p>
  <p>The two issues I cannot resolve are:</p>
  <ol>
  <li>I want to display United States as the first choice in the picker, followed by an alphabetical listing of all other countries.</li>
  </ol>
  <p>I've thought about using NSPredicate or NSCompoundPredicate but that's just filtering out values. I thought about creating multiple fetchrequests and filtering everything except the US and then the other shows everything but the US. That seemed like a waste, and I wasn't entirely sure how to combine them.</p>
  <ol start="2">
  <li>Based on the user's selection, I need to populate three variables (id, name, and abbr).</li>
  </ol>
  <p>I can bind to the name and it works just fine. Likewise, I can bind the picker to the abbr and it works. However, I cannot figure out how to update all 3 variables as a picker only has a single binding. I tried writing a function that sets all of these variables onTap within the ForEach but that didn't seem like a good plan (or maybe it is?).</p>
  <p>Here's some code:</p>
  <pre><code>@FetchRequest(sortDescriptors: [SortDescriptor(\.name)] var countries: FetchedResults&lt;Picker_Country&gt;
  
  // Load and decode the JSON from remote URL without caching
  
      func loadCountryData() async {
          
          let config = URLSessionConfiguration.default
          config.requestCachePolicy = .reloadIgnoringLocalCacheData
          config.urlCache = nil
          let URLSessionNoCache = URLSession(configuration: config)
  
          guard let url = URL(string: &quot;https://api.foo.com/general/pickers/country_select&quot;) else {
              print(&quot;Invalid URL&quot;)
              return
          }
  
          do {
              let (data, _) = try await URLSessionNoCache.data(from: url)
              let decoder = JSONDecoder()
              decoder.dateDecodingStrategy = .iso8601
              let countries = try decoder.decode([CountryOptions].self, from: data)
              
              await MainActor.run {
                  setCountryArray(with: countries)
              }
  
          } catch {
              print(&quot;Invalid Data&quot;)
          }
      }
      
      func setCountryArray(with downloadedCountryOptions: [CountryOptions]) {
          for countries in downloadedCountryOptions {
              let countryPicker = Picker_Country(context: moc)
              
              countryPicker.id =  Int16(countries.id)
              countryPicker.name = countries.name
              countryPicker.abbr = countries.abbr
          }
          try? moc.save()
      }
  </code></pre>
  <p>and finally, here is my picker.</p>
  <p>(Note: wrappedName and wrappedAbbr and are just vars that allow me to not have to nil coalesce. They correspond directly to name and abbr.)</p>
  <p>Obviously by using .tag I am showing the name but only setting the abbr, which is also what the selection is bound to. That's the question of how to set the id, name, and abbr on user selection.</p>
  <pre><code>Picker(&quot;Country&quot;, selection: $createUser.countryAbbr) {
      ForEach(countries) { country in
          Text(country.wrappedName).tag(country.wrappedAbbr)
      } // End ForEach
  } // End Picker
  .pickerStyle(WheelPickerStyle())
  .padding()
  .labelsHidden()
  </code></pre>