title: SwifUI ForEach List keeps modified values when reloading a @Published array inside ObservableObject
body: <p>I have a SwiftUI List populated using a ForEach loop binded to a @Published array inside an ObservableObject</p>
  <p>Elements in the list can be modified with an on/off flag. When the list is cleared out all items seems removed from the UI but when the data is refetched and loaded inside the @Published array the UI still shows the state of te previously modified elements. As you can see in the following video:</p>
  <p><a href="https://i.stack.imgur.com/M6ztS.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M6ztS.gif" alt="List not refreshing demo" /></a></p>
  <p>The code to reproduce it:</p>
  <pre><code>struct ListView: View {
      
      @ObservedObject private var viewModel = ListViewModel()
  
      var body: some View {
              VStack {
                  List {
                      ForEach(viewModel.list, id: \.self) { element in
                          ElementRow(element: element)
                      }
                  }
                  HStack {
                      Button(action: { viewModel.fetch() }) { Text(&quot;Refresh&quot;) }
                      Button(action: { viewModel.remove() }) { Text(&quot;Remove&quot;) }
                  }
              }.onAppear {
                  viewModel.fetch()
              }
          }
      }
  
  struct ElementRow: View {
      @ObservedObject var element: ElementViewModel
      
      var body: some View {
          HStack {
              Text(element.id)
              Spacer()
              Toggle(&quot;&quot;, isOn: $element.on )
          }
      }
  }
  
  class ListViewModel : ObservableObject {
      
      @Published var list: [ElementViewModel] = []
      
      func fetch() {
          list.append(contentsOf: [ElementViewModel(id: &quot;0&quot;, on: false), ElementViewModel(id: &quot;1&quot;, on: false)])
      }
      func remove() {
          list.removeAll()
      }
  }
  
  class ElementViewModel : ObservableObject, Hashable {
      
      var id: String = &quot;&quot;
      @Published var on: Bool = false
      
      init(id: String, on: Bool) {
          self.id = id
          self.on = on
      }
      static func == (lhs: ElementViewModel, rhs: ElementViewModel) -&gt; Bool {
          lhs.id == rhs.id
      }
      func hash(into hasher: inout Hasher) {
          hasher.combine(id)
      }
  }
  
  </code></pre>
  <p>What needs to be changed to make that all the elements in the list remains off when it's refreshed?</p>