title: How to Pass State from List Selection in Modal to Parent in SwiftUI
body: <p>I have a view where a user can see a list of items. When they click a button, a modal pops up with a List Selection where they can choose items. I would like these selections to update the list on the parent view.</p>
  
  <p>I am using an ObservedObject for the SelectedItems:</p>
  
  <pre><code>class SelectedItems: ObservableObject, Hashable {
      @Published var items: [Item] = []
  
      func hash(into hasher: inout Hasher) {
          hasher.combine(items)
      }
  
      init(items: [Item]) {
          self.items = items
      }
  }
  </code></pre>
  
  <p>On the parent view, I simply loop through them:</p>
  
  <pre><code>...
  
  @ObservedObject var selectedItems: SelectedItems
  
  ...
  
  List(self.selectedItems.items) { item in
    Text(item.name)
  }
  </code></pre>
  
  <p>The problem is in the modal view:</p>
  
  <pre><code>...
  
  @ObservedObject var selectedItems: SelectedItems
  var items: [Item]
  
  ...
  
  List(items, id: \.self, selection: selectedItems) { item in
    Text(item.name)
  }
  .environment(\.editMode, .constant(EditMode.active))
  </code></pre>
  
  <p>I made sure that <code>selectedIngredients</code> conforms to <code>Hashable</code> as required by <code>List Selection</code>, but it's still throwing a number of errors.</p>
  
  <p>The specific error in this case is Generic parameter <code>'SelectionValue' could not be inferred</code>.</p>
  
  <p>I have been at this for a couple days and any help would really be appreciated!</p>