title: How make work a Picker with an ObservedObject in SwiftUI?
body: <p>I'm trying to get a list of Datacenters from a Rest API and show them in a Picker, so the user can choose one. When I do it with a static list it works fine. However, retrieving the Datacenters dinamically seems not to work fine. </p>
  
  <p>I'm using Xcode 11 (GM)</p>
  
  <p>This is the Datacenter Object</p>
  
  <pre class="lang-swift prettyprint-override"><code>struct Datacenter:Codable, Hashable, Identifiable{ 
      let id: String
      var location: String
  }
  </code></pre>
  
  <p>This is the ObservedObject (it has the property datacenters that is an array of Datacenter objects)</p>
  
  <pre class="lang-swift prettyprint-override"><code>@ObservedObject var datacenters_controller : DatacentersController
  @State private var selectedDatacenter = 0
  </code></pre>
  
  <p>This was my first attempt:</p>
  
  <pre class="lang-swift prettyprint-override"><code>Picker(selection: $selectedDatacenter, label: Text("Datacenter")) {
     ForEach(0 ..&lt; datacenters_controller.datacenters.count) {
       Text(self.datacenters_controller.datacenters[$0].location)
     }
  }
  </code></pre>
  
  <p>Swift complained with the following error:</p>
  
  <pre><code>ForEach&lt;Range&lt;Int&gt;, Int, Text&gt; count (4) != its initial count (0). `ForEach(_:content:)` should only be used for *constant* data. Instead conform data to `Identifiable` or use `ForEach(_:id:content:)` and provide an explicit `id`!
  </code></pre>
  
  <p>Then I switched to:</p>
  
  <pre class="lang-swift prettyprint-override"><code>Picker(selection: $selectedDatacenter, label: Text("Datacenter")) {
     ForEach(datacenters_controller.datacenters) { datacenter in
        Text(datacenter.location)
     }
  }
  </code></pre>
  
  <p>It "works" (no error), but the result is not the expected because although I can select a datacenter, it is not "stored", not shown in the Picker as selected.</p>
  
  <p>Actual result</p>
  
  <p><a href="https://i.stack.imgur.com/2DZqp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2DZqp.png" alt="Picker without selection"></a></p>
  
  <p>Expected result</p>
  
  <p><a href="https://i.stack.imgur.com/wIeqc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wIeqc.png" alt="Picker with a datacenter selected"></a></p>
  
  <p>Any idea? What I'm doing wrong?</p>